import { AmbientAlert } from "../feedback/AmbientAlert.mjs";
import { PDFViewer } from "./pdfViewer/PDFViewer.mjs";
import { validateFilesImageType } from "./utils/fileUtils.mjs";
import { ImageSlider } from "./imageSlider/ImageSlider.mjs";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
//#region src/UI/fileViewer/FileViewer.jsx
const defaultFieldMapping = {
	filePath: "filePath",
	blobFile: "blobFile",
	fileName: "fileName",
	fileExtension: "fileExtension",
	primaryText: "primaryText",
	secondaryText: "secondaryText"
};
const FileViewer = (props) => {
	const { data, fieldMapping = defaultFieldMapping, acceptedFileExtensions, ...otherProps } = props;
	const { t } = useTranslation();
	const filteredData = useMemo(() => {
		if (!acceptedFileExtensions || acceptedFileExtensions?.length === 0) return data;
		if (data instanceof Array && data?.length > 0) return data?.filter((item) => acceptedFileExtensions?.includes(item?.[fieldMapping?.fileExtension]));
		else return acceptedFileExtensions?.includes(data?.[fieldMapping?.fileExtension]) ? data : null;
	}, [
		acceptedFileExtensions,
		data,
		fieldMapping
	]);
	const fileType = useMemo(() => {
		if (filteredData instanceof Array) return validateFilesImageType(filteredData, fieldMapping?.fileExtension);
		return filteredData?.[fieldMapping?.fileExtension];
	}, [fieldMapping, filteredData]);
	const viewer = useMemo(() => {
		switch (fileType) {
			case "pdf": return /* @__PURE__ */ React.createElement(PDFViewer, {
				fileUrl: filteredData?.[fieldMapping?.filePath],
				blobPDF: filteredData?.[fieldMapping?.blobFile],
				...otherProps
			});
			case "image": return /* @__PURE__ */ React.createElement(ImageSlider, {
				images: filteredData,
				fieldMapping,
				...otherProps
			});
			default: return /* @__PURE__ */ React.createElement(AmbientAlert, {
				alertMessage: t("Unable to view file"),
				showAlert: true,
				alertSeverity: "error"
			});
		}
	}, [
		fileType,
		data,
		fieldMapping,
		otherProps
	]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, viewer);
};
//#endregion
export { FileViewer };

//# sourceMappingURL=FileViewer.mjs.map