import { useEffect, useState } from 'react';
import * as _ from 'lodash';
export const useEditorStickyHeader = (props) => {
    const [zIndex, setZIndex] = useState();
    const [lines, setLines] = useState(0);
    useEffect(() => {
        if (props.editor) {
            const compute = _.debounce(() => {
                let element = props.editor.getContainerDomNode().querySelector('.sticky-widget');
                if (element) {
                    _.defer(() => {
                        var _a, _b;
                        let lines = ((_a = element.querySelector('.sticky-widget-lines')) === null || _a === void 0 ? void 0 : _a.childNodes) || [];
                        setZIndex((_b = element.computedStyleMap().get('z-index')) === null || _b === void 0 ? void 0 : _b.value);
                        setLines(lines.length);
                    });
                }
            }, 200);
            // could already be on scrolled sticky state
            let res = setTimeout(() => {
                compute();
                res = null;
            }, 500);
            const l1 = props.editor.onDidScrollChange(() => {
                compute();
            });
            const l2 = props.editor.onDidDispose(() => {
                l1.dispose();
                l2.dispose();
            });
            return () => {
                l1.dispose();
                l2.dispose();
                if (res) {
                    clearTimeout(res);
                }
            };
        }
    }, [props.editor]);
    return {
        zIndex,
        lines
    };
};
//# sourceMappingURL=useEditorStickyHeader.js.map