"use strict";

exports.__esModule = true;
exports.CollectionToolbarActionsGroupResponsiveLayout = void 0;
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _mobxReactLite = require("mobx-react-lite");
var _ToolbarItem = require("../ToolbarItem/ToolbarItem");
var _ToolbarGroupScrollWidthBox = require("./ToolbarGroupScrollWidthBox");
var _SearchOrCustomFilter = require("./SearchOrCustomFilter");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _InitialLoadingConditional = require("../InitialLoadingConditional");
var _CollectionToolbarSkeletonItem = require("./CollectionToolbarSkeletonItem");
var _ToolbarOverflowMenu = require("./ToolbarOverflowMenu");
var _useToolbarOverflowItems = require("./useToolbarOverflowItems");
var _toolbarResponsiveConstants = require("../../state/Toolbar/toolbarResponsiveConstants");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionToolbar/CollectionToolbarActionsGroupResponsiveLayout.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 _CollectionToolbarActionsGroupResponsiveLayout(props) {
  const {
    state,
    left,
    viewsToolbarItem,
    filtersElement,
    MoreFiltersButton,
    multiLevelSorting,
    customColumns,
    exportButton,
    importButton,
    search,
    showCustomColumnsOnTheLeft,
    tableGridSwitchButton,
    viewTypeState
  } = props;
  const toolbarState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    toolbar: {
      responsive
    }
  } = toolbarState;
  const overflowItems = (0, _useToolbarOverflowItems.useToolbarOverflowItems)(toolbarState, {
    customColumns,
    multiLevelSorting,
    exportButton,
    importButton,
    MoreFiltersButton,
    viewTypeState
  });
  const overflowItemCount = overflowItems.primaryItems.length + overflowItems.secondaryItems.length + (overflowItems.layoutSwitchConfig ? 1 : 0);

  // Don't show a "More" menu for a single item — keep it as an inline icon.
  const shouldOverflow = responsive._shouldOverflow && overflowItemCount > 1;

  // Track width of non-group content hidden during overflow so the algorithm
  // doesn't overestimate available space when deciding whether to exit overflow.
  // Tied to effective shouldOverflow (not just _shouldOverflow) so the single-item
  // bypass doesn't cause a mismatch between DOM and algorithm.
  (0, _react.useEffect)(() => {
    responsive._overflowHiddenContentWidth = tableGridSwitchButton && shouldOverflow ? _toolbarResponsiveConstants.LAYOUT_SWITCH_BUTTON_WIDTH : 0;
  }, [responsive, !!tableGridSwitchButton, shouldOverflow]);
  let child = /*#__PURE__*/_react.default.createElement(_react.Fragment, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 66,
      columnNumber: 5
    }
  }, left ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, viewsToolbarItem && /*#__PURE__*/_react.default.createElement(_InitialLoadingConditional.InitialLoadingConditional, {
    state: toolbarState,
    loadingElement: /*#__PURE__*/_react.default.createElement(_CollectionToolbarSkeletonItem.CollectionToolbarSkeletonItem, {
      dataHook: "toolbar-views-skeleton",
      width: "100px",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 73,
        columnNumber: 17
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 70,
      columnNumber: 13
    }
  }, viewsToolbarItem), filtersElement) : viewsToolbarItem ? filtersElement : undefined, !shouldOverflow && tableGridSwitchButton, !shouldOverflow && MoreFiltersButton && /*#__PURE__*/_react.default.createElement(_ToolbarGroupScrollWidthBox.ToolbarGroupScrollWidthBox, {
    state: responsive.filters,
    gap: "SP2",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 91,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(MoreFiltersButton, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 92,
      columnNumber: 11
    }
  })), !shouldOverflow && /*#__PURE__*/_react.default.createElement(_ToolbarGroupScrollWidthBox.ToolbarGroupScrollWidthBox, {
    state: responsive.actions,
    gap: "SP2",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 97,
      columnNumber: 9
    }
  }, customColumns && showCustomColumnsOnTheLeft && customColumns, multiLevelSorting, exportButton && /*#__PURE__*/(0, _react.cloneElement)(exportButton, {
    toolbarType: 'default'
  }), importButton && /*#__PURE__*/(0, _react.cloneElement)(importButton, {
    toolbarType: 'default'
  }), customColumns && !showCustomColumnsOnTheLeft && customColumns), shouldOverflow && (exportButton || importButton) && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    display: "none",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 113,
      columnNumber: 9
    }
  }, exportButton && /*#__PURE__*/(0, _react.cloneElement)(exportButton, {
    toolbarType: 'default'
  }), importButton && /*#__PURE__*/(0, _react.cloneElement)(importButton, {
    toolbarType: 'default'
  })), shouldOverflow && /*#__PURE__*/_react.default.createElement(_ToolbarOverflowMenu.ToolbarOverflowMenu, {
    primaryItems: overflowItems.primaryItems,
    secondaryItems: overflowItems.secondaryItems,
    layoutSwitchConfig: overflowItems.layoutSwitchConfig,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 122,
      columnNumber: 9
    }
  }), search && /*#__PURE__*/_react.default.createElement(_SearchOrCustomFilter.SearchOrCustomFilter, {
    state: state,
    search: search,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 129,
      columnNumber: 18
    }
  }));
  child = /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    ref: element => {
      responsive._contentElement = element;
    },
    dataHook: "horizontal-overflow-box",
    minWidth: 0,
    direction: "horizontal",
    gap: "SP2",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 134,
      columnNumber: 5
    }
  }, child);
  child = /*#__PURE__*/_react.default.createElement(_ToolbarItem.ToolbarItem, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 147,
      columnNumber: 11
    }
  }, child);
  child = /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    ref: element => {
      responsive._measurementElement = element;
    },
    minWidth: 0,
    flex: 1,
    align: "right",
    direction: "horizontal",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 150,
      columnNumber: 5
    }
  }, child);
  return child;
}
const CollectionToolbarActionsGroupResponsiveLayout = exports.CollectionToolbarActionsGroupResponsiveLayout = (0, _mobxReactLite.observer)(_CollectionToolbarActionsGroupResponsiveLayout);
//# sourceMappingURL=CollectionToolbarActionsGroupResponsiveLayout.js.map