import { useEffect as e, useMemo as t } from "react";
import { cn as n } from "@ryuzaki13/react-foundation-lib/utils";
import { CaptionsIcon as r, CaptionsOffIcon as i, ChevronLeftIcon as a, ChevronRightIcon as o, DownloadIcon as s, GalleryThumbnailsIcon as c, ImageOffIcon as l, LoaderCircleIcon as u, Maximize2Icon as d, Minimize2Icon as f, XIcon as p, ZoomInIcon as m, ZoomOutIcon as h } from "lucide-react";
import { jsx as g } from "react/jsx-runtime";
import _, { isImageSlide as v } from "yet-another-react-lightbox";
import y from "yet-another-react-lightbox/plugins/captions";
import b from "yet-another-react-lightbox/plugins/counter";
import x from "yet-another-react-lightbox/plugins/download";
import S from "yet-another-react-lightbox/plugins/fullscreen";
import C from "yet-another-react-lightbox/plugins/thumbnails";
import w from "yet-another-react-lightbox/plugins/zoom";
//#region src/image/lib/buildImageViewerSlides.ts
function T(e) {
	return Number.isFinite(e) && e > 0;
}
function E(e, t) {
	let n = e.width === void 0 ? e.density === void 0 ? 0 : t * e.density : e.width;
	return T(n) ? Math.round(n) : null;
}
function D(e) {
	let { intrinsicWidth: t, intrinsicHeight: n } = e;
	if (t === void 0 || n === void 0 || !T(t) || !T(n)) return;
	let r = /* @__PURE__ */ new Map();
	for (let i of e.candidates ?? []) {
		let e = E(i, t);
		e === null || r.has(e) || r.set(e, {
			src: i.src,
			width: e,
			height: Math.max(1, Math.round(e * n / t))
		});
	}
	let i = [...r.values()].sort((e, t) => e.width - t.width);
	return i.length > 0 ? i : void 0;
}
function O(e) {
	return e.map((e) => {
		let t = T(e.intrinsicWidth ?? 0) && T(e.intrinsicHeight ?? 0);
		return {
			src: e.src,
			alt: e.alt,
			width: t ? e.intrinsicWidth : void 0,
			height: t ? e.intrinsicHeight : void 0,
			srcSet: D(e),
			title: e.title === void 0 ? e.alt : e.title,
			description: e.description,
			thumbnail: e.thumbnail,
			download: e.download
		};
	});
}
//#endregion
//#region src/image/lib/resolveImageViewerLabels.ts
var k = {
	previous: "Предыдущее изображение",
	next: "Следующее изображение",
	close: "Закрыть просмотр",
	slide: "Изображение",
	carousel: "Карусель изображений",
	lightbox: "Просмотр изображений",
	photoGallery: "Галерея изображений",
	slideCounter: "{index} из {total}",
	zoomIn: "Увеличить",
	zoomOut: "Уменьшить",
	enterFullscreen: "Перейти в полноэкранный режим",
	exitFullscreen: "Выйти из полноэкранного режима",
	thumbnails: "Миниатюры",
	showThumbnails: "Показать миниатюры",
	hideThumbnails: "Скрыть миниатюры",
	caption: "Подпись изображения",
	showCaptions: "Показать подписи",
	hideCaptions: "Скрыть подписи",
	download: "Скачать изображение"
};
function A(e) {
	let t = {
		...k,
		...e
	};
	return {
		Previous: t.previous,
		Next: t.next,
		Close: t.close,
		Slide: t.slide,
		Carousel: t.carousel,
		Lightbox: t.lightbox,
		"Photo gallery": t.photoGallery,
		"{index} of {total}": t.slideCounter,
		"Zoom in": t.zoomIn,
		"Zoom out": t.zoomOut,
		"Enter Fullscreen": t.enterFullscreen,
		"Exit Fullscreen": t.exitFullscreen,
		Thumbnails: t.thumbnails,
		"Show thumbnails": t.showThumbnails,
		"Hide thumbnails": t.hideThumbnails,
		Caption: t.caption,
		"Show captions": t.showCaptions,
		"Hide captions": t.hideCaptions,
		Download: t.download
	};
}
var j = {
	viewer: "acj1dM",
	icon: "jt3y3m",
	loadingIcon: "_2SAWIU",
	imageViewerSpin: "_1GqI3h"
}, M = "var(--_image-viewer-top-row-height)";
function N({ open: T, images: E, index: D = 0, onClose: k, onIndexChange: N, features: P, loop: F = !1, closeOnBackdropClick: I = !0, closeOnPullDown: L = !0, labels: R, className: z, style: B, onRuntimeMounted: V }) {
	e(() => {
		V();
	}, [V]);
	let H = t(() => O(E), [E]), U = Number.isFinite(D) ? Math.trunc(D) : 0, W = H.length > 0 ? Math.min(Math.max(U, 0), H.length - 1) : 0, G = E.some((e) => (e.title === void 0 ? e.alt : e.title) != null || e.description !== void 0 && e.description !== null), K = P?.captions ?? G, q = P?.counter ?? H.length > 1, J = P?.download ?? !1, Y = P?.fullscreen ?? !0, X = P?.thumbnails ?? H.length > 1, Z = P?.zoom ?? !0, Q = t(() => [
		...K ? [y] : [],
		...q ? [b] : [],
		...J ? [x] : [],
		...Y ? [S] : [],
		...X ? [C] : [],
		...Z ? [w] : []
	], [
		K,
		q,
		J,
		Y,
		X,
		Z
	]), $ = t(() => A(R), [R]);
	return /* @__PURE__ */ g(_, {
		open: T && H.length > 0,
		close: k,
		index: W,
		slides: H,
		plugins: Q,
		className: n(j.viewer, z),
		portal: { container: { style: B } },
		labels: $,
		carousel: { finite: !F },
		controller: {
			closeOnBackdropClick: I,
			closeOnPullDown: L
		},
		captions: { showToggle: !0 },
		counter: {
			separator: " / ",
			container: { style: K ? { top: M } : void 0 }
		},
		thumbnails: { showToggle: !0 },
		download: { download: ({ slide: e, saveAs: t }) => {
			if (!(!v(e) || e.download === !1)) {
				if (typeof e.download == "string") {
					t(e.download);
					return;
				}
				if (typeof e.download == "object") {
					t(e.download.url, e.download.filename);
					return;
				}
				t(e.src);
			}
		} },
		on: { view: ({ index: e }) => {
			e !== W && N?.(e);
		} },
		render: {
			iconPrev: () => /* @__PURE__ */ g(a, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconNext: () => /* @__PURE__ */ g(o, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconClose: () => /* @__PURE__ */ g(p, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconLoading: () => /* @__PURE__ */ g(u, {
				"aria-hidden": "true",
				className: n(j.icon, j.loadingIcon)
			}),
			iconError: () => /* @__PURE__ */ g(l, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconZoomIn: () => /* @__PURE__ */ g(m, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconZoomOut: () => /* @__PURE__ */ g(h, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconEnterFullscreen: () => /* @__PURE__ */ g(d, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconExitFullscreen: () => /* @__PURE__ */ g(f, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconThumbnailsVisible: () => /* @__PURE__ */ g(c, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconThumbnailsHidden: () => /* @__PURE__ */ g(c, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconCaptionsVisible: () => /* @__PURE__ */ g(r, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconCaptionsHidden: () => /* @__PURE__ */ g(i, {
				"aria-hidden": "true",
				className: j.icon
			}),
			iconDownload: () => /* @__PURE__ */ g(s, {
				"aria-hidden": "true",
				className: j.icon
			})
		}
	});
}
//#endregion
export { N as default };

//# sourceMappingURL=ImageViewerRuntime-RN49by8Y.js.map