import _IconButton from "@mui/material/IconButton";
/*!
 * Copyright (c) 2022-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 { memo, useCallback } from "react";
import { useTranslation } from "../i18n.generated/i18n.js";
import { DeleteIcon } from "../icons.generated/index.js";
import { MuiPropsContext } from "../MuiPropsContext.js";
import { useOdysseyDesignTokens } from "../OdysseyDesignTokensContext.js";
import { Tooltip } from "../Tooltip.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const PreviewContainer = styled.div(({
  isDisabled,
  odysseyDesignTokens
}) => ({
  color: isDisabled ? odysseyDesignTokens.TypographyColorDisabled : "inherit",
  marginBlockStart: odysseyDesignTokens.Spacing2,
  pointerEvents: isDisabled ? "none" : "auto"
}));
const UploadedFileContainer = styled.div({
  display: "flex",
  justifyContent: "space-between",
  alignItems: "center",
  button: {
    transform: "scale(0)"
  },
  "&:hover, &:focus-within, &:focus": {
    button: {
      transform: "scale(1)"
    }
  }
}, ({
  odysseyDesignTokens
}) => ({
  padding: `${odysseyDesignTokens.Spacing1} ${odysseyDesignTokens.Spacing2}`,
  borderRadius: odysseyDesignTokens.BorderRadiusMain,
  transition: `background-color ${odysseyDesignTokens.TransitionTimingMain}`,
  "&:hover, &:focus-within": {
    backgroundColor: odysseyDesignTokens.HueNeutral100
  },
  "&:focus": {
    borderColor: odysseyDesignTokens.FocusOutlineColorPrimary,
    boxShadow: `0 0 0 2px ${odysseyDesignTokens.FocusOutlineColorPrimary}`,
    outline: `${odysseyDesignTokens.FocusOutlineWidthMain} ${odysseyDesignTokens.FocusOutlineStyle} transparent`
  }
}));
const UploadedFile = ({
  name,
  onFileRemove
}) => {
  const {
    t
  } = useTranslation();
  const odysseyDesignTokens = useOdysseyDesignTokens();
  const deleteHandler = useCallback(() => {
    onFileRemove?.(name);
  }, [onFileRemove, name]);
  const renderDeleteButton = useCallback(muiProps => {
    return _jsx(_IconButton, {
      ...muiProps,
      "aria-label": t("fileupload.removefile.text"),
      onClick: deleteHandler,
      size: "small",
      children: _jsx(DeleteIcon, {})
    });
  }, [deleteHandler, t]);
  return _jsxs(UploadedFileContainer, {
    odysseyDesignTokens: odysseyDesignTokens,
    tabIndex: 0,
    children: [name, _jsx(Tooltip, {
      ariaType: "description",
      placement: "top",
      text: t("fileupload.removefile.text"),
      children: _jsx(MuiPropsContext.Consumer, {
        children: renderDeleteButton
      })
    })]
  });
};
const FileUploadPreview = ({
  fileNames,
  isDisabled,
  onFileRemove
}) => {
  const odysseyDesignTokens = useOdysseyDesignTokens();
  return _jsx(PreviewContainer, {
    "data-file-preview-container": "true",
    isDisabled: isDisabled,
    odysseyDesignTokens: odysseyDesignTokens,
    children: fileNames?.map((name, index) => _jsx(UploadedFile, {
      name: name,
      onFileRemove: onFileRemove
    }, `${index}-${name}`))
  });
};
const MemoizedFileUploadPreview = memo(FileUploadPreview);
MemoizedFileUploadPreview.displayName = "FileUploadPreview";
export { MemoizedFileUploadPreview as FileUploadPreview };
//# sourceMappingURL=FileUploadPreview.js.map