"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useStickyItemTop = void 0;
const sdk_1 = require("@cntrl-site/sdk");
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
const useLayoutContext_1 = require("../useLayoutContext");
function useStickyItemTop(item, sectionHeightMap, sectionId) {
    const layoutId = (0, useLayoutContext_1.useLayoutContext)();
    const data = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Position, (item, layoutId) => {
        if (!layoutId)
            return;
        return item.area[layoutId];
    }, (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined, sectionId, [layoutId]);
    const top = data ? data.top : layoutId ? item.area[layoutId].top : 0;
    const sticky = layoutId ? item.sticky[layoutId] : undefined;
    return sticky ? top - sticky.from : 0;
}
exports.useStickyItemTop = useStickyItemTop;
