import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useEffect } from 'react';
import { Box } from '@primer/react';
import { useScreencapture, useToast } from '../index.js';
import { lazyWithPreload, WithSuspense } from '../../utils/index.js';
import { useLayoutStore } from '../../state/index.js';
import '../../../style/screencapture/index.css';
const Screencapture = WithSuspense(lazyWithPreload(() => import('../../components/screencapture/Screencapture')));
const Capture = (props) => {
    const { onStartCapture } = props;
    useEffect(() => {
        onStartCapture();
    }, []);
    return _jsx(_Fragment, {});
};
const ScreencaptureContent = (props) => {
    //  const { screenshotDisplay } = props;
    const { enqueueToast } = useToast();
    const { setScreencapture, hideScreencapture } = useLayoutStore();
    const handleScreencapture = (screenCapture) => {
        setScreencapture(screenCapture);
        hideScreencapture();
        enqueueToast('Screen is captured.', { variant: 'success' });
    };
    return (_jsx(Box, { children: _jsx(Screencapture, { onEndCapture: handleScreencapture, children: ({ onStartCapture }) => _jsx(Capture, { onStartCapture: onStartCapture }) }) }));
};
export const LayoutScreencapture = () => {
    const { screenshot } = useLayoutStore();
    const { displayScreencapture, closeScreencapture } = useScreencapture();
    useEffect(() => {
        if (screenshot && screenshot.open) {
            displayScreencapture(() => (_jsx(ScreencaptureContent, { screenshotDisplay: screenshot })));
        }
        else {
            closeScreencapture();
        }
    }, [screenshot]);
    return _jsx(_Fragment, {});
};
export default LayoutScreencapture;
