'use client';
import * as React from 'react';
import { exportChartsAsImage } from './image-export-utils';
import { useRtl } from './utilities';
export const useImageExport = (componentRef, hideLegends, isChartCartesian = true)=>{
    const cartesianChartRef = React.useRef(null);
    const chartContainerRef = React.useRef(null);
    const legendsRef = React.useRef(null);
    const isRTL = useRtl();
    React.useImperativeHandle(componentRef, ()=>{
        var _cartesianChartRef_current;
        const chartContainer = isChartCartesian ? (_cartesianChartRef_current = cartesianChartRef.current) === null || _cartesianChartRef_current === void 0 ? void 0 : _cartesianChartRef_current.chartContainer : chartContainerRef.current;
        return {
            chartContainer: chartContainer !== null && chartContainer !== void 0 ? chartContainer : null,
            toImage: (opts)=>{
                var _legendsRef_current;
                return exportChartsAsImage([
                    {
                        container: chartContainer
                    }
                ], hideLegends ? undefined : (_legendsRef_current = legendsRef.current) === null || _legendsRef_current === void 0 ? void 0 : _legendsRef_current.toSVG, isRTL, opts);
            }
        };
    }, [
        hideLegends,
        isChartCartesian,
        isRTL
    ]);
    return {
        cartesianChartRef,
        chartContainerRef,
        legendsRef
    };
};
