"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionListRow = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _Fade = require("../Fade");
var _mobxReactLite = require("mobx-react-lite");
var _CollectionListItem = require("../CollectionListItem");
var _CollectionItemActions = require("../CollectionItemActions");
var _designSystem = require("@wix/design-system");
var _state = require("../../state");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionListRow/CollectionListRow.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 CollectionListRow = exports.CollectionListRow = (0, _mobxReactLite.observer)(function CollectionListRow({
  fade,
  element,
  collection,
  keyedItem,
  dataHook,
  ...rest
}) {
  const toolbarState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const [state] = (0, _react.useState)(() => new _state.ItemActionsState({
    collection,
    keyedItem,
    fade: 'idle',
    reportBi: toolbarState.reportBi
  }));
  const {
    type: CollectionListItemComponent,
    props: collectionListItemProps
  } = element;
  (0, _react.useEffect)(() => {
    if (state.keyedItem !== keyedItem) {
      state.keyedItem = keyedItem;
    }
  }, [keyedItem]);
  const transformColumn = columnElement => {
    const {
      props
    } = columnElement;
    const overrides = _CollectionListItem.RowActionsColumnSlot.isElementOf(columnElement) ? {
      width: 100,
      align: 'right',
      value: /*#__PURE__*/_react.default.createElement(_CollectionItemActions.CollectionItemActions, {
        state: state,
        collection: collection,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 63,
          columnNumber: 13
        }
      })
    } : {
      value: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        dataHook: "collection-list-column",
        color: "D20",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 68,
          columnNumber: 13
        }
      }, props.children)
    };
    return {
      ...props,
      ...overrides
    };
  };
  let child = /*#__PURE__*/_react.default.createElement(CollectionListItemComponent, (0, _extends2.default)({
    showDivider: true
  }, collectionListItemProps, {
    transformColumn: transformColumn,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 81,
      columnNumber: 5
    }
  }));
  if (fade) {
    child = /*#__PURE__*/_react.default.createElement(_Fade.Fade, (0, _extends2.default)({
      timeout: 650
    }, rest, {
      onExiting: node => {
        state.onFadeStart();
        void (rest.onExiting == null ? void 0 : rest.onExiting(node));
      },
      onExited: node => {
        state.onFadeDone();
        void (rest.onExited == null ? void 0 : rest.onExited(node));
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 90,
        columnNumber: 7
      }
    }), /*#__PURE__*/_react.default.createElement("div", {
      "data-hook": dataHook,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 102,
        columnNumber: 9
      }
    }, child));
  }
  return child;
});
//# sourceMappingURL=CollectionListRow.js.map