require("./chunk-9hOWP6kD.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
let lucide_react = require("lucide-react");
//#region ../widgets/src/components/MediaRenderer.tsx
function MediaRenderer({ src, alt = "Media", objectFit = "cover", focusPoint, mediaType = "image", poster, autoplay = false, loop = false, muted = true, controls = true }) {
	const hasValidSrc = src && src.trim() !== "";
	const objectPosition = focusPoint?.replace("-", " ");
	if (!hasValidSrc) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "bg-muted @container flex h-full w-full items-center justify-center",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "text-muted-foreground flex flex-col items-center gap-2",
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(mediaType === "video" ? lucide_react.Video : lucide_react.Image, { className: "size-5 @[10rem]:size-12" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
				className: "hidden text-sm @[10rem]:block",
				children: mediaType === "video" ? "No video selected" : "No image selected"
			})]
		})
	});
	const isContainMode = objectFit === "contain";
	const blurSrc = isContainMode ? `${src}?tr=bl-50` : void 0;
	if (mediaType === "video") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VideoRenderer, {
		src,
		poster,
		controls,
		autoplay,
		loop,
		muted,
		objectFit,
		objectPosition,
		isContainMode,
		blurSrc
	});
	if (isContainMode) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "relative h-full w-full overflow-hidden",
		children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
				src: blurSrc,
				alt: "",
				className: "absolute inset-0 h-full w-full object-cover",
				"aria-hidden": "true"
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
				className: "pointer-events-none absolute inset-0 bg-black/30",
				"aria-hidden": "true"
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
				src,
				alt,
				className: "relative z-10 h-full w-full object-contain"
			})
		]
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
		src,
		alt,
		className: `h-full w-full object-${objectFit}`,
		style: objectPosition ? { objectPosition } : void 0
	});
}
function VideoRenderer({ src, poster, controls, autoplay, loop, muted, objectFit, objectPosition, isContainMode, blurSrc }) {
	const videoRef = (0, react.useRef)(null);
	const handleEnded = (0, react.useCallback)(() => {
		if (!loop) return;
		const video = videoRef.current;
		if (!video) return;
		video.currentTime = 0;
		video.play().catch(() => {});
	}, [loop]);
	const noInteraction = !controls ? "pointer-events-none" : "";
	const blurredBgSrc = isContainMode ? poster ? `${poster}?tr=bl-50` : blurSrc : void 0;
	if (isContainMode && blurredBgSrc) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "relative h-full w-full overflow-hidden",
		children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
				src: blurredBgSrc,
				alt: "",
				className: "absolute inset-0 h-full w-full object-cover",
				"aria-hidden": "true"
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
				className: "pointer-events-none absolute inset-0 bg-black/30",
				"aria-hidden": "true"
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)("video", {
				ref: videoRef,
				src,
				poster,
				controls,
				autoPlay: autoplay,
				loop,
				muted,
				playsInline: true,
				onEnded: handleEnded,
				className: `relative z-10 h-full w-full object-contain ${noInteraction}`,
				children: "Your browser does not support the video tag."
			})
		]
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("video", {
		ref: videoRef,
		src,
		poster,
		controls,
		autoPlay: autoplay,
		loop,
		muted,
		playsInline: true,
		onEnded: handleEnded,
		className: `h-full w-full object-${objectFit} ${noInteraction}`,
		style: objectPosition ? { objectPosition } : void 0,
		children: "Your browser does not support the video tag."
	});
}
/**
* Converts a ShareableItem to MediaRenderer props.
* Replaces the createWidgetFromShareable → ScreenRenderer pattern.
*/
function getMediaPropsFromShareable(item) {
	if ((item.kind === "video" || !!item.videoUrl) && item.videoUrl) {
		const result = {
			mediaType: "video",
			src: item.videoUrl,
			alt: item.title ?? "Video"
		};
		if (item.imageUrl != null) result.poster = item.imageUrl;
		return result;
	}
	const result = {
		mediaType: "image",
		alt: item.title || "Image",
		objectFit: "cover"
	};
	if (item.imageUrl != null) result.src = item.imageUrl;
	return result;
}
/**
* Extracts media props from an ImageWidget/VideoWidget schema.
* Used by CarouselWidget for slide.content rendering.
*/
function getMediaPropsFromWidgetSchema(schema) {
	const props = schema.props;
	const resource = props.resource;
	const useCustomUrl = props.useCustomUrl;
	const focusPoint = props.focusPoint;
	const displayFit = props.displayFit;
	if (schema.type === "VideoWidget") {
		const result = {
			mediaType: "video",
			autoplay: props.autoplay ?? false,
			loop: props.loop ?? false,
			muted: props.muted ?? true,
			controls: props.controls ?? true,
			objectFit: displayFit ?? "cover",
			focusPoint
		};
		if (useCustomUrl) {
			if (typeof props.src === "string") result.src = props.src;
			if (typeof props.poster === "string") result.poster = props.poster;
		} else if (resource) {
			if (resource.videoUrl) result.src = resource.videoUrl;
			else if (typeof props.src === "string") result.src = props.src;
			if (resource.imageUrl) result.poster = resource.imageUrl;
			else if (typeof props.poster === "string") result.poster = props.poster;
		} else {
			if (typeof props.src === "string") result.src = props.src;
			if (typeof props.poster === "string") result.poster = props.poster;
		}
		return result;
	}
	const result = {
		mediaType: "image",
		alt: props.alt ?? "Image",
		objectFit: displayFit ?? "cover",
		focusPoint
	};
	if (useCustomUrl) {
		if (typeof props.src === "string") result.src = props.src;
	} else if (resource) {
		if (resource.imageUrl) result.src = resource.imageUrl;
		else if (typeof props.src === "string") result.src = props.src;
		if (resource.title) result.alt = resource.title;
	} else if (typeof props.src === "string") result.src = props.src;
	return result;
}
//#endregion
Object.defineProperty(exports, "MediaRenderer", {
	enumerable: true,
	get: function() {
		return MediaRenderer;
	}
});
Object.defineProperty(exports, "getMediaPropsFromShareable", {
	enumerable: true,
	get: function() {
		return getMediaPropsFromShareable;
	}
});
Object.defineProperty(exports, "getMediaPropsFromWidgetSchema", {
	enumerable: true,
	get: function() {
		return getMediaPropsFromWidgetSchema;
	}
});

//# sourceMappingURL=MediaRenderer-BI_FoJAZ.cjs.map