"use strict";

exports.__esModule = true;
exports.KanbanCardTags = void 0;
var _designSystem = require("@wix/design-system");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/Kanban/KanbanCardTags.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const MAX_VISIBLE_TAGS = 3;
function _KanbanCardTags({
  item,
  dataHook,
  maxVisibleTags = MAX_VISIBLE_TAGS
}) {
  var _tags$privateTags;
  const {
    tagsCollectionState
  } = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const [isExpanded, setIsExpanded] = (0, _react.useState)(false);
  if (!(tagsCollectionState != null && tagsCollectionState.tagsManagementState)) {
    return null;
  }
  const tags = (tagsCollectionState._getTags == null ? void 0 : tagsCollectionState._getTags(item)) ?? item.tags;
  if (!(tags != null && (_tags$privateTags = tags.privateTags) != null && (_tags$privateTags = _tags$privateTags.tagIds) != null && _tags$privateTags.length)) {
    return null;
  }
  const tagItems = tags.privateTags.tagIds.map(tagId => tagsCollectionState.tagsManagementState.items.find(tag => tag.id === tagId)).filter(Boolean);
  if (tagItems.length === 0) {
    return null;
  }
  const visibleTags = isExpanded ? tagItems : tagItems.slice(0, maxVisibleTags);
  const hiddenCount = tagItems.length - maxVisibleTags;
  const hasMoreTags = hiddenCount > 0;
  return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    dataHook: dataHook,
    direction: "horizontal",
    gap: "tiny",
    verticalAlign: "middle",
    flexWrap: "wrap",
    marginTop: "6px",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 59,
      columnNumber: 5
    }
  }, visibleTags.map(tag => /*#__PURE__*/_react.default.createElement(_designSystem.Tag, {
    key: tag.id,
    id: tag.id,
    dataHook: `${dataHook}-${tag.id}`,
    size: "tiny",
    removable: false,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 68,
      columnNumber: 9
    }
  }, tag.name)), hasMoreTags && !isExpanded && /*#__PURE__*/_react.default.createElement(_designSystem.Tag, {
    id: `${dataHook}-toggle`,
    dataHook: `${dataHook}-toggle`,
    size: "tiny",
    removable: false,
    onClick: () => setIsExpanded(!isExpanded),
    skin: "lightOutlined",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 79,
      columnNumber: 9
    }
  }, `+${hiddenCount}`));
}
const KanbanCardTags = exports.KanbanCardTags = (0, _mobxReactLite.observer)(_KanbanCardTags);
//# sourceMappingURL=KanbanCardTags.js.map