"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useExportCanvas: ()=>useExportCanvas
});
const react_cjs_namespaceObject = require("../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const export_canvas_cjs_namespaceObject = require("../utils/export-canvas.cjs");
function useExportCanvas() {
    const reactFlowInstance = (0, react_cjs_namespaceObject.useReactFlow)();
    const [isExporting, setIsExporting] = (0, external_react_namespaceObject.useState)(false);
    const [error, setError] = (0, external_react_namespaceObject.useState)(null);
    const [lastResult, setLastResult] = (0, external_react_namespaceObject.useState)(null);
    const exportToImage = (0, external_react_namespaceObject.useCallback)(async (options)=>{
        setIsExporting(true);
        setError(null);
        await new Promise((resolve)=>setTimeout(resolve, 0));
        try {
            const result = await (0, export_canvas_cjs_namespaceObject.exportCanvasToImage)(reactFlowInstance, options);
            setLastResult(result);
            return result;
        } catch (err) {
            const exportError = err instanceof Error ? err : new Error('Failed to export canvas');
            setError(exportError);
            return null;
        } finally{
            setIsExporting(false);
        }
    }, [
        reactFlowInstance
    ]);
    const downloadAsImage = (0, external_react_namespaceObject.useCallback)(async (filename, options)=>{
        setIsExporting(true);
        setError(null);
        await new Promise((resolve)=>setTimeout(resolve, 0));
        try {
            await (0, export_canvas_cjs_namespaceObject.downloadCanvasAsImage)(reactFlowInstance, filename, options);
        } catch (err) {
            const downloadError = err instanceof Error ? err : new Error('Failed to download canvas');
            setError(downloadError);
        } finally{
            setIsExporting(false);
        }
    }, [
        reactFlowInstance
    ]);
    const copyToClipboard = (0, external_react_namespaceObject.useCallback)(async (options)=>{
        setIsExporting(true);
        setError(null);
        await new Promise((resolve)=>setTimeout(resolve, 0));
        try {
            await (0, export_canvas_cjs_namespaceObject.copyCanvasToClipboard)(reactFlowInstance, options);
        } catch (err) {
            const copyError = err instanceof Error ? err : new Error('Failed to copy canvas to clipboard');
            setError(copyError);
        } finally{
            setIsExporting(false);
        }
    }, [
        reactFlowInstance
    ]);
    const clearError = (0, external_react_namespaceObject.useCallback)(()=>{
        setError(null);
    }, []);
    return {
        isExporting,
        error,
        lastResult,
        exportToImage,
        downloadAsImage,
        copyToClipboard,
        clearError
    };
}
exports.useExportCanvas = __webpack_exports__.useExportCanvas;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useExportCanvas"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
