import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { createContext, useState, useContext } from 'react';
import { LayoutScreencapture } from './layouts/index.js';
export const ScreencaptureContext = createContext({
    closeScreencapture: () => { },
    displayScreencapture: (nextScreencapture) => { },
});
export function useScreencapture() {
    const context = useContext(ScreencaptureContext);
    if (!context)
        throw new Error('useContext must be inside a provider with a value.');
    return context;
}
/**
 * The type for the Screencapture context provider.
 */
export const ScreencaptureContextProvider = ScreencaptureContext.Provider;
export function ScreencaptureProvider({ children = null, zIndex = 9999, disableDarken = false, screenshotSurface = undefined, }) {
    const defaultScreencaptureSurface = {
        position: 'fixed',
        top: 0,
        left: 0,
        width: '100%',
        height: '100%',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: disableDarken ? 'initial' : 'rgba(0, 0, 0, 0.5)',
        zIndex,
    };
    const [screenshot, setScreencapture] = useState({
        open: false,
        render: (closeScreencapture) => _jsx(_Fragment, {}),
    });
    const displayScreencapture = (nextScreencapture) => {
        setScreencapture({
            open: true,
            render: nextScreencapture,
        });
    };
    const closeScreencapture = () => {
        setScreencapture({
            open: false,
            render: (closeScreencapture) => _jsx(_Fragment, {}),
        });
    };
    return (_jsxs(ScreencaptureContextProvider, { value: { closeScreencapture, displayScreencapture }, children: [_jsx(LayoutScreencapture, {}), children, screenshot.open &&
                (screenshotSurface ? (screenshotSurface(screenshot.render(closeScreencapture))) : (_jsx("div", { style: defaultScreencaptureSurface, children: screenshot.render(closeScreencapture) })))] }));
}
