"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FileUploadPreview = void 0;
var _IconButton2 = _interopRequireDefault(require("@mui/material/IconButton"));
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _react = require("react");
var _i18n = require("../i18n.generated/i18n.cjs");
var _index = require("../icons.generated/index.cjs");
var _MuiPropsContext = require("../MuiPropsContext.cjs");
var _OdysseyDesignTokensContext = require("../OdysseyDesignTokensContext.cjs");
var _Tooltip = require("../Tooltip.cjs");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*!
 * 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.
 */

const PreviewContainer = _styled.default.div(({
  isDisabled,
  odysseyDesignTokens
}) => ({
  color: isDisabled ? odysseyDesignTokens.TypographyColorDisabled : "inherit",
  marginBlockStart: odysseyDesignTokens.Spacing2,
  pointerEvents: isDisabled ? "none" : "auto"
}));
const UploadedFileContainer = _styled.default.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
  } = (0, _i18n.useTranslation)();
  const odysseyDesignTokens = (0, _OdysseyDesignTokensContext.useOdysseyDesignTokens)();
  const deleteHandler = (0, _react.useCallback)(() => {
    onFileRemove?.(name);
  }, [onFileRemove, name]);
  const renderDeleteButton = (0, _react.useCallback)(muiProps => {
    return (0, _jsxRuntime.jsx)(_IconButton2.default, {
      ...muiProps,
      "aria-label": t("fileupload.removefile.text"),
      onClick: deleteHandler,
      size: "small",
      children: (0, _jsxRuntime.jsx)(_index.DeleteIcon, {})
    });
  }, [deleteHandler, t]);
  return (0, _jsxRuntime.jsxs)(UploadedFileContainer, {
    odysseyDesignTokens: odysseyDesignTokens,
    tabIndex: 0,
    children: [name, (0, _jsxRuntime.jsx)(_Tooltip.Tooltip, {
      ariaType: "description",
      placement: "top",
      text: t("fileupload.removefile.text"),
      children: (0, _jsxRuntime.jsx)(_MuiPropsContext.MuiPropsContext.Consumer, {
        children: renderDeleteButton
      })
    })]
  });
};
const FileUploadPreview = ({
  fileNames,
  isDisabled,
  onFileRemove
}) => {
  const odysseyDesignTokens = (0, _OdysseyDesignTokensContext.useOdysseyDesignTokens)();
  return (0, _jsxRuntime.jsx)(PreviewContainer, {
    "data-file-preview-container": "true",
    isDisabled: isDisabled,
    odysseyDesignTokens: odysseyDesignTokens,
    children: fileNames?.map((name, index) => (0, _jsxRuntime.jsx)(UploadedFile, {
      name: name,
      onFileRemove: onFileRemove
    }, `${index}-${name}`))
  });
};
const MemoizedFileUploadPreview = exports.FileUploadPreview = (0, _react.memo)(FileUploadPreview);
MemoizedFileUploadPreview.displayName = "FileUploadPreview";
//# sourceMappingURL=FileUploadPreview.cjs.map