"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.GridCardItem = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _state = require("../../state");
var _mobxReactLite = require("mobx-react-lite");
var _useGridItemActions = require("./useGridItemActions");
var _ActionModal = require("../ActionModal");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/Grid/GridCardItem.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); }
function _GridCardItem(props) {
  const {
    state,
    keyedItem,
    index,
    actionCell,
    preset,
    renderItem,
    draggable,
    droppable,
    dragging,
    dragHandleProps
  } = props;
  const toolbarState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const [itemActionsState] = _react.default.useState(() => new _state.ItemActionsState({
    collection: state.collection,
    keyedItem,
    fade: 'idle',
    reportBi: toolbarState.reportBi
  }));
  const {
    item
  } = keyedItem;
  const {
    collection,
    calcGridProps: {
      cardFooterSize
    }
  } = state;
  const {
    itemName
  } = collection;
  const renderProps = (renderItem == null ? void 0 : renderItem(item, index)) ?? {};
  const {
    backgroundImageNode
  } = renderProps;
  const imagePlacement = renderProps.imagePlacement ?? state.imagePlacement;
  const {
    primaryAction,
    settingsMenu
  } = (0, _useGridItemActions.useGridItemActions)({
    actionCell,
    item,
    index,
    gridState: state,
    keyedItem,
    itemActionsState,
    imagePlacement
  });
  const textProps = (() => {
    if (preset === 'empty') {
      return {
        title: undefined,
        subtitle: undefined,
        footer: undefined
      };
    }
    return {
      title: (renderProps == null ? void 0 : renderProps.title) || itemName(item) || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "\u200B"),
      subtitle: preset === 'full' || preset === 'footer' ? (renderProps == null ? void 0 : renderProps.subtitle) || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "\u200B") : undefined,
      footer: preset === 'footer' ? /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        height: "42px",
        direction: "vertical",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 102,
          columnNumber: 11
        }
      }, renderProps == null ? void 0 : renderProps.footer) : undefined
    };
  })();
  const primaryActionProps = _react.default.useMemo(() => {
    const merged = {
      ...(primaryAction ?? (renderProps == null ? void 0 : renderProps.primaryActionProps))
    };
    return Object.keys(merged).length > 0 ? merged : undefined;
  }, [primaryAction, renderProps == null ? void 0 : renderProps.primaryActionProps]);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_designSystem.CardGalleryItem, (0, _extends2.default)({
    tabIndex: 0,
    dataHook: "grid-card-item"
  }, renderProps, {
    skin: "outlined",
    size: cardFooterSize,
    imagePlacement: imagePlacement,
    backgroundImageNode: backgroundImageNode == null ? /*#__PURE__*/_react.default.createElement(_designSystem.Image, {
      borderRadius: 0,
      height: "100%",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 128,
        columnNumber: 13
      }
    }) : /*#__PURE__*/(0, _react.isValidElement)(backgroundImageNode) ? (/*#__PURE__*/(0, _react.cloneElement)(backgroundImageNode, {
      style: {
        borderRadius: 0
      }
    })) : backgroundImageNode
  }, textProps, {
    primaryActionProps: primaryActionProps,
    settingsMenu: settingsMenu ?? renderProps.settingsMenu,
    draggable: draggable,
    dragging: dragging,
    droppable: droppable,
    dragHandleProps: dragHandleProps,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 119,
      columnNumber: 7
    }
  })), /*#__PURE__*/_react.default.createElement(_ActionModal.MessageActionModal, (0, _extends2.default)({
    state: itemActionsState.confirmModal
  }, itemActionsState.confirmModal.value, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 147,
      columnNumber: 7
    }
  })));
}
const GridCardItem = exports.GridCardItem = (0, _mobxReactLite.observer)(_GridCardItem);
//# sourceMappingURL=GridCardItem.js.map