"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const material_1 = require("@mui/material");
const styles_1 = require("@mui/material/styles");
const react_1 = require("react");
const react_photo_view_1 = require("react-photo-view");
const constants_1 = require("./constants");
const classes = {
    root: `${constants_1.PREFIX}-root`
};
const Root = (0, styles_1.styled)(react_photo_view_1.PhotoSlider, {
    name: constants_1.PREFIX,
    slot: 'Root',
    overridesResolver: (_props, styles) => styles.root
})(() => ({}));
const BaseLightbox = (props) => {
    const { images = [], index, onClose, visible = true, afterClose, onIndexChange, toolbarRender, toolbarButtons } = props, rest = tslib_1.__rest(props, ["images", "index", "onClose", "visible", "afterClose", "onIndexChange", "toolbarRender", "toolbarButtons"]);
    // STATE
    const [currentImageIndex, setCurrentImageIndex] = (0, react_1.useState)(index || 0);
    const handleIndexChange = (0, react_1.useCallback)((index) => {
        onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(index);
        setCurrentImageIndex(index);
    }, [onIndexChange, setCurrentImageIndex]);
    /**
     * Renders root object
     */
    return ((0, jsx_runtime_1.jsx)(Root, Object.assign({}, rest, { className: classes.root, images: images, visible: visible && index !== -1, index: currentImageIndex, onIndexChange: handleIndexChange, onClose: onClose, afterClose: afterClose, loadingElement: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { color: 'primary' }), toolbarRender: toolbarRender
            ? toolbarRender
            : () => {
                return toolbarButtons;
            } })));
};
exports.default = BaseLightbox;
