/*!
 * 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.
 */

import { memo, useCallback, useMemo } from "react";
import { MenuButton } from "../../Buttons/MenuButton.js";
import { MenuItem } from "../../Buttons/MenuItem.js";
import { useTranslation } from "../../i18n.generated/i18n.js";
import { jsx as _jsx } from "react/jsx-runtime";
const LayoutSwitcher = ({
  availableLayouts,
  currentLayout,
  setCurrentLayout
}) => {
  const {
    t
  } = useTranslation();
  const changeLayout = useCallback(value => {
    setCurrentLayout(value);
  }, [setCurrentLayout]);
  const memoizedMenuItems = useMemo(() => availableLayouts.map(value => ({
    value,
    onClick: () => changeLayout(value),
    label: t(`dataview.layout.${value}`)
  })), [availableLayouts, changeLayout, t]);
  return _jsx(MenuButton, {
    ariaLabel: t("dataview.layout.arialabel"),
    buttonLabel: t(`dataview.layout.${currentLayout}`),
    menuAlignment: "right",
    shouldCloseOnSelect: false,
    children: memoizedMenuItems.map(({
      value,
      onClick,
      label
    }) => _jsx(MenuItem, {
      isSelected: currentLayout === value,
      onClick: onClick,
      children: label
    }, value))
  });
};
const MemoizedLayoutSwitcher = memo(LayoutSwitcher);
MemoizedLayoutSwitcher.displayName = "LayoutSwitcher";
export { MemoizedLayoutSwitcher as LayoutSwitcher };
//# sourceMappingURL=LayoutSwitcher.js.map