"use client";
import { __rest } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
import { jsx } from 'react/jsx-runtime';
import { Image } from 'fumadocs-core/framework';
import { useState } from 'react';
import { Uncontrolled } from '../../node_modules/.pnpm/react-medium-image-zoom@5.4.1_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/react-medium-image-zoom/dist/Uncontrolled.mjs';

function getImageSrc(src) {
    if (typeof src === 'string')
        return src;
    if (typeof src === 'object') {
        // Next.js
        if ('default' in src)
            return src.default.src;
        return src.src;
    }
    return '';
}
/**
 * @example
 * <ImageZoom src="URL" fallbackSrc="/my-placeholder.png" />
 */
function ImageZoom(_a) {
    var _b;
    var { zoomInProps, children, rmiz, fallbackSrc = 'https://r2.d8ger.com/default.webp' } = _a, props = __rest(_a, ["zoomInProps", "children", "rmiz", "fallbackSrc"]);
    const [imgSrc, setImgSrc] = useState(getImageSrc(props.src));
    // fallback logic
    const handleError = () => {
        console.warn('ImageZoom check error:', imgSrc, fallbackSrc);
        if (imgSrc !== fallbackSrc) {
            setImgSrc(fallbackSrc);
        }
    };
    return (jsx(Uncontrolled, Object.assign({ zoomMargin: 20, wrapElement: "span" }, rmiz, { zoomImg: Object.assign(Object.assign({ src: imgSrc, sizes: undefined }, zoomInProps), { onError: handleError }), children: children !== null && children !== void 0 ? children : (jsx(Image, Object.assign({}, props, { src: imgSrc, onError: handleError, sizes: "(max-width: 400px) 100vw, 300px", style: { width: '100%', height: 'auto', maxWidth: 300 }, alt: (_b = props.alt) !== null && _b !== void 0 ? _b : '', width: 300, height: 225 }))) })));
}

export { ImageZoom };
