var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useEffect, useState, useRef, useImperativeHandle, forwardRef, } from 'react';
import WaterMark from '../WaterMark';
import { LightOff, LightOn } from '../../assets/icons';
import { Content } from './styles';
const R2UModelViewer = forwardRef((props, ref) => {
    const { exitImgSrc = 'https://sdk.r2u.io/assets/exit-icon.png', expandImgSrc = 'https://sdk.r2u.io/assets/expand-icon.png', popup = true, children = null, waterMarkPosition, refViewerPopup, ModelViewerElement, refViewerFunctions } = props, viewerProps = __rest(props, ["exitImgSrc", "expandImgSrc", "popup", "children", "waterMarkPosition", "refViewerPopup", "ModelViewerElement", "refViewerFunctions"]);
    const [expanded, setExpanded] = useState(false);
    const expand = () => {
        setExpanded(true);
    };
    const close = () => {
        setExpanded(false);
    };
    useEffect(() => {
        if (refViewerPopup && refViewerPopup.current) {
            refViewerPopup.current.addEventListener('mousedown', ((event) => {
                event.preventDefault();
                event.stopPropagation();
                event.stopImmediatePropagation();
                return false;
            }));
        }
    }, [refViewerPopup]);
    const bloomRef = useRef(null);
    const [bloomIsOn, setBloomIsOn] = useState(false);
    const [glb, setGlb] = useState(viewerProps.glbSrc);
    useImperativeHandle(ref, () => ({
        updateGlb: (newGlb) => {
            setGlb(newGlb);
        },
    }), []);
    return (React.createElement(Content, { expanded: expanded, bloom: bloomIsOn },
        React.createElement("div", { className: "viewer-container" }, glb && (React.createElement(ModelViewerElement, Object.assign({ ref: refViewerFunctions, componentDidMount: viewerProps.componentDidMount, onClick: viewerProps.onClick, onSessionTimeCollect: viewerProps.onSessionTimeCollect }, viewerProps, { glbSrc: glb }),
            children,
            popup && (React.createElement("button", { className: "expand-button", type: "button", onClick: expand },
                React.createElement("img", { className: "expand-image", alt: "", src: expandImgSrc }))),
            waterMarkPosition && React.createElement(WaterMark, { position: waterMarkPosition })))),
        popup && expanded && (React.createElement("div", { className: "background", onMouseDown: close },
            React.createElement("div", { className: "viewer-container popup" }, glb && (React.createElement(ModelViewerElement, Object.assign({ ref: bloomRef, componentDidMount: viewerProps.componentDidMount, onClick: viewerProps.onClick, onSessionTimeCollect: viewerProps.onSessionTimeCollect }, viewerProps, { enableBloomButton: false, glbSrc: glb }),
                children,
                viewerProps.bloom && (React.createElement("button", { className: "bloomButton", type: "button", onMouseDown: (e) => e.stopPropagation(), onClick: () => {
                        setBloomIsOn(!bloomIsOn);
                        if (bloomRef.current)
                            bloomRef.current.updateBloom(!bloomIsOn);
                    } }, bloomIsOn ? (React.createElement(LightOn, { className: "lamp" })) : (React.createElement(LightOff, { className: "lamp" })))),
                React.createElement("button", { className: "exit-button", type: "button", onClick: close },
                    React.createElement("img", { alt: "", src: exitImgSrc })),
                waterMarkPosition && (React.createElement(WaterMark, { position: waterMarkPosition })))))))));
});
R2UModelViewer.displayName = 'R2UModelViewer';
export default R2UModelViewer;
//# sourceMappingURL=index.js.map