import _Skeleton from "@mui/material/Skeleton";
/*!
 * 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 styled from "@emotion/styled";
import { useCallback } from "react";
import { MuiPropsContext } from "../../MuiPropsContext.js";
import { useOdysseyDesignTokens } from "../../OdysseyDesignTokensContext.js";
import { Tooltip } from "../../Tooltip.js";
import { jsx as _jsx } from "react/jsx-runtime";
const AppSwitcherAppWrapperComponent = styled("li", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  margin: "auto",
  marginBlockEnd: odysseyDesignTokens.Spacing3,
  textAlign: "center"
}));
const AppSwitcherAppLinkComponent = styled("a", {
  shouldForwardProp: prop => !["isSelected", "odysseyDesignTokens"].includes(prop)
})(({
  odysseyDesignTokens,
  isSelected
}) => ({
  display: "inline-block",
  margin: "auto",
  padding: odysseyDesignTokens.Spacing1,
  backgroundColor: isSelected ? odysseyDesignTokens.PalettePrimaryLighter : "transparent",
  borderRadius: odysseyDesignTokens.BorderRadiusTight,
  transition: `background-color ${odysseyDesignTokens.TransitionDurationMain}`,
  "&:hover, &:focus": {
    backgroundColor: odysseyDesignTokens.HueNeutral50
  }
}));
const AppSwitcherAppSkeletonWrapperComponent = styled("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "inline-block",
  margin: "auto",
  padding: odysseyDesignTokens.Spacing1
}));
const AppSwitcherAppImgComponent = styled("img", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "block",
  width: odysseyDesignTokens.Spacing6,
  height: odysseyDesignTokens.Spacing6
}));
export const AppSwitcherApp = ({
  appIconDefaultUrl,
  appIconSelectedUrl,
  appName,
  label,
  linkUrl,
  selectedAppName
}) => {
  const odysseyDesignTokens = useOdysseyDesignTokens();
  const isSelected = appName === selectedAppName;
  const renderAppIconLink = useCallback(muiProps => _jsx(AppSwitcherAppLinkComponent, {
    ...muiProps,
    "aria-current": isSelected ? "page" : undefined,
    href: linkUrl,
    isSelected: isSelected,
    odysseyDesignTokens: odysseyDesignTokens,
    children: _jsx(AppSwitcherAppImgComponent, {
      odysseyDesignTokens: odysseyDesignTokens,
      role: "presentation",
      src: isSelected ? appIconSelectedUrl : appIconDefaultUrl
    })
  }), [odysseyDesignTokens, isSelected, linkUrl, appIconDefaultUrl, appIconSelectedUrl]);
  return _jsx(AppSwitcherAppWrapperComponent, {
    odysseyDesignTokens: odysseyDesignTokens,
    children: _jsx(Tooltip, {
      ariaType: "label",
      placement: "right",
      text: label,
      translate: "no",
      children: _jsx(MuiPropsContext.Consumer, {
        children: renderAppIconLink
      })
    })
  });
};
export const AppSwitcherAppSkeleton = () => {
  const odysseyDesignTokens = useOdysseyDesignTokens();
  return _jsx(AppSwitcherAppWrapperComponent, {
    odysseyDesignTokens: odysseyDesignTokens,
    children: _jsx(AppSwitcherAppSkeletonWrapperComponent, {
      odysseyDesignTokens: odysseyDesignTokens,
      children: _jsx(_Skeleton, {
        height: odysseyDesignTokens.Spacing6,
        variant: "rounded",
        width: odysseyDesignTokens.Spacing6
      })
    })
  });
};
//# sourceMappingURL=AppSwitcherApp.js.map