/*! ratio-ui · design system for knowledge sharing · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
import { Button } from "../../core/Button/Button2.js";
import "../../core/Button/index.js";
import { Drawer } from "../Drawer/Drawer.js";
import { useCallback, useEffect, useMemo } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/layout/FileDrawer/FileDrawer.tsx
/**
* Drawer that displays file content in an embedded iframe.
* Accepts either a `src` URL or raw `content` (which is converted to a blob URL internally).
* Optionally shows a download button when `downloadFilename` is provided.
*/
var FileDrawer = ({ isOpen, onClose, title, content, contentType = "text/html", src, downloadFilename, downloadLabel = "Download", closeLabel = "Close" }) => {
	const blobUrl = useMemo(() => {
		if (!isOpen || src || !content) return null;
		return URL.createObjectURL(new Blob([content], { type: contentType }));
	}, [
		isOpen,
		content,
		contentType,
		src
	]);
	useEffect(() => {
		return () => {
			if (blobUrl) URL.revokeObjectURL(blobUrl);
		};
	}, [blobUrl]);
	const iframeSrc = src ?? blobUrl;
	const handleDownload = useCallback(() => {
		if (!iframeSrc) return;
		const a = document.createElement("a");
		a.href = iframeSrc;
		a.download = downloadFilename ?? "download";
		a.click();
	}, [iframeSrc, downloadFilename]);
	return /* @__PURE__ */ jsxs(Drawer, {
		isOpen,
		onClose,
		children: [
			/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Heading, { children: title }) }),
			/* @__PURE__ */ jsx(Drawer.Body, {
				className: "flex flex-col",
				children: iframeSrc && /* @__PURE__ */ jsx("iframe", {
					src: iframeSrc,
					sandbox: "allow-same-origin",
					className: "w-full flex-1 rounded border border-border bg-white",
					title
				})
			}),
			/* @__PURE__ */ jsxs(Drawer.Footer, { children: [downloadFilename && iframeSrc && /* @__PURE__ */ jsx(Button, {
				onClick: handleDownload,
				variant: "primary",
				children: downloadLabel
			}), /* @__PURE__ */ jsx(Button, {
				onClick: onClose,
				variant: "secondary",
				children: closeLabel
			})] })
		]
	});
};
//#endregion
export { FileDrawer };

//# sourceMappingURL=FileDrawer.js.map