"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LayoutSwitcher = void 0;
var _react = require("react");
var _MenuButton = require("../../Buttons/MenuButton.cjs");
var _MenuItem = require("../../Buttons/MenuItem.cjs");
var _i18n = require("../../i18n.generated/i18n.cjs");
var _jsxRuntime = require("react/jsx-runtime");
/*!
 * Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */

const LayoutSwitcher = ({
  availableLayouts,
  currentLayout,
  setCurrentLayout
}) => {
  const {
    t
  } = (0, _i18n.useTranslation)();
  const changeLayout = (0, _react.useCallback)(value => {
    setCurrentLayout(value);
  }, [setCurrentLayout]);
  const memoizedMenuItems = (0, _react.useMemo)(() => availableLayouts.map(value => ({
    value,
    onClick: () => changeLayout(value),
    label: t(`dataview.layout.${value}`)
  })), [availableLayouts, changeLayout, t]);
  return (0, _jsxRuntime.jsx)(_MenuButton.MenuButton, {
    ariaLabel: t("dataview.layout.arialabel"),
    buttonLabel: t(`dataview.layout.${currentLayout}`),
    menuAlignment: "right",
    shouldCloseOnSelect: false,
    children: memoizedMenuItems.map(({
      value,
      onClick,
      label
    }) => (0, _jsxRuntime.jsx)(_MenuItem.MenuItem, {
      isSelected: currentLayout === value,
      onClick: onClick,
      children: label
    }, value))
  });
};
const MemoizedLayoutSwitcher = exports.LayoutSwitcher = (0, _react.memo)(LayoutSwitcher);
MemoizedLayoutSwitcher.displayName = "LayoutSwitcher";
//# sourceMappingURL=LayoutSwitcher.cjs.map