"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableTopNotification = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _Fade = require("../Fade");
var _Collapse = require("../Collapse");
var _mobxReactLite = require("mobx-react-lite");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _TableTopNotificationState = require("./TableTopNotificationState");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TableTopNotification/TableTopNotification.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 _TableTopNotification(props) {
  const {
    onClose,
    showCloseButton = !!onClose,
    onAfterClose,
    onAfterOpen,
    hideOnSearch,
    children,
    appearance = 'standard',
    ...rest
  } = props;
  const toolbarCollectionState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    collection,
    totalStickyContentHeight
  } = toolbarCollectionState;
  const {
    _topNotification: topNotification,
    query: {
      search
    }
  } = collection;
  const [state] = (0, _react.useState)(() => new _TableTopNotificationState.TableTopNotificationState({
    topNotification,
    getStickyContentHeight: () => toolbarCollectionState.totalStickyContentHeight,
    reportBI: toolbarCollectionState.reportBi
  }));
  const targetRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => state.init(), []);
  const {
    position
  } = state;
  const {
    data: text,
    show
  } = topNotification;
  let child;
  if (hideOnSearch && !search.isEmpty) {
    child = null;
  } else {
    child = /*#__PURE__*/_react.default.createElement(_Collapse.Collapse, {
      timeout: 300,
      state: topNotification,
      onEntered: onAfterOpen,
      style: {
        flexShrink: 0,
        ...(position === 'sticky' && totalStickyContentHeight != null && {
          position: 'sticky',
          top: totalStickyContentHeight,
          zIndex: 1100
        }),
        width: '100%'
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 76,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Table.SubToolbar, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 91,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(_Fade.Fade, {
      timeout: 300,
      in: show,
      unmountOnExit: true,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 92,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      paddingTop: "15px",
      paddingBottom: "15px",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 93,
        columnNumber: 13
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.SectionHelper, (0, _extends2.default)({}, rest, {
      dataHook: "table-top-notification",
      showCloseButton: showCloseButton,
      onClose: e => {
        topNotification.clickClose(onAfterClose);
        onClose == null || onClose(e);
      },
      appearance: appearance,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 94,
        columnNumber: 15
      }
    }), text, children)))));
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, child, /*#__PURE__*/_react.default.createElement("div", {
    ref: el => {
      targetRef.current = el;
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 117,
      columnNumber: 7
    }
  }));
}
const TableTopNotification = exports.TableTopNotification = (0, _mobxReactLite.observer)(_TableTopNotification);
TableTopNotification.displayName = 'TableTopNotification';
//# sourceMappingURL=TableTopNotification.js.map