"use strict";

exports.__esModule = true;
exports.LayoutSwitchButton = void 0;
var _mobxReactLite = require("mobx-react-lite");
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _react2 = require("@wix/bex-core/react");
var _layoutConfig = require("./layoutConfig");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/LayoutSwitchButton/LayoutSwitchButton.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 _LayoutSwitchButton({
  state,
  options
}) {
  const {
    translate: t,
    internalExperiments
  } = (0, _react2.useWixPatternsContainer)();
  const {
    viewType
  } = state;
  const isLayoutToggleRedesignEnabled = internalExperiments == null ? void 0 : internalExperiments.enabled('specs.cairo.layout-toggle.redesign');
  const dropdownOptions = (0, _react.useMemo)(() => options.map(option => (0, _designSystem.listItemSelectBuilder)({
    id: option,
    title: t(_layoutConfig.layoutConfig[option].translationKey),
    prefix: _layoutConfig.layoutConfig[option].icon,
    dataHook: `layout-option-${option}`
  })), [t, options]);
  if (!isLayoutToggleRedesignEnabled) {
    return /*#__PURE__*/_react.default.createElement(_designSystem.SegmentedToggle, {
      size: "small",
      dataHook: "layout-switch-toggle-button",
      selected: viewType,
      onClick: (_, value) => {
        if (state.viewType === value) {
          return;
        }
        state.changeViewType(value);
      },
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 42,
        columnNumber: 7
      }
    }, options.map(option => /*#__PURE__*/_react.default.createElement(_designSystem.SegmentedToggle.Icon, {
      key: option,
      value: option,
      dataHook: `toggle-option-${option}`,
      tooltipText: t(_layoutConfig.layoutConfig[option].translationKey),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 54,
        columnNumber: 11
      }
    }, _layoutConfig.layoutConfig[option].icon)));
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.DropdownBase, {
    dataHook: "layout-switch-popover",
    options: dropdownOptions,
    selectedId: viewType,
    showArrow: true,
    onSelect: option => {
      const selectedOption = option.id;
      const index = options.indexOf(selectedOption);
      state.reportLayoutOptionClicked(selectedOption, index);
      if (viewType !== selectedOption) {
        state.changeViewType(selectedOption);
      }
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 68,
      columnNumber: 5
    }
  }, ({
    toggle
  }) => /*#__PURE__*/_react.default.createElement(_designSystem.Tooltip, {
    content: t('cairo.table.layout.switchLayout'),
    size: "medium",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 83,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.IconButton, {
    dataHook: "layout-switch-button",
    size: "small",
    priority: "secondary",
    "aria-haspopup": "menu",
    onClick: () => {
      state.reportLayoutSwitch();
      toggle();
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 84,
      columnNumber: 11
    }
  }, _layoutConfig.layoutConfig[viewType].icon)));
}
const LayoutSwitchButton = exports.LayoutSwitchButton = (0, _mobxReactLite.observer)(_LayoutSwitchButton);
//# sourceMappingURL=LayoutSwitchButton.js.map