var $f7b82bedbb70abac$exports = require("./Collection.cjs");
var $68boB$react = require("react");
var $68boB$reactariaprivatevirtualizerScrollView = require("react-aria/private/virtualizer/ScrollView");
var $68boB$reactstatelyprivatevirtualizeruseVirtualizerState = require("react-stately/private/virtualizer/useVirtualizerState");
var $68boB$reactariaprivatevirtualizerVirtualizerItem = require("react-aria/private/virtualizer/VirtualizerItem");


function $parcel$interopDefault(a) {
  return a && a.__esModule ? a.default : a;
}

function $parcel$export(e, n, v, s) {
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}

$parcel$export(module.exports, "Virtualizer", function () { return $fd02a37bc042f4f4$export$89be5a243e59c4b2; });
/*
 * Copyright 2024 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 




const $fd02a37bc042f4f4$var$VirtualizerContext = /*#__PURE__*/ (0, $68boB$react.createContext)(null);
const $fd02a37bc042f4f4$var$LayoutContext = /*#__PURE__*/ (0, $68boB$react.createContext)(null);
function $fd02a37bc042f4f4$export$89be5a243e59c4b2(props) {
    let { children: children, layout: layoutProp, layoutOptions: layoutOptions } = props;
    let layout = (0, $68boB$react.useMemo)(()=>typeof layoutProp === 'function' ? new layoutProp() : layoutProp, [
        layoutProp
    ]);
    let renderer = (0, $68boB$react.useMemo)(()=>({
            isVirtualized: true,
            layoutDelegate: layout,
            dropTargetDelegate: layout.getDropTargetFromPoint ? layout : undefined,
            CollectionRoot: $fd02a37bc042f4f4$var$CollectionRoot,
            CollectionBranch: $fd02a37bc042f4f4$var$CollectionBranch
        }), [
        layout
    ]);
    return /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement((0, $f7b82bedbb70abac$exports.CollectionRendererContext).Provider, {
        value: renderer
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement($fd02a37bc042f4f4$var$LayoutContext.Provider, {
        value: {
            layout: layout,
            layoutOptions: layoutOptions
        }
    }, children));
}
function $fd02a37bc042f4f4$var$CollectionRoot({ collection: collection, persistedKeys: persistedKeys, scrollRef: scrollRef, renderDropIndicator: renderDropIndicator }) {
    let { layout: layout, layoutOptions: layoutOptions } = (0, $68boB$react.useContext)($fd02a37bc042f4f4$var$LayoutContext);
    let layoutOptions2 = layout.useLayoutOptions?.();
    let state = (0, $68boB$reactstatelyprivatevirtualizeruseVirtualizerState.useVirtualizerState)({
        layout: layout,
        collection: collection,
        renderView: (type, item)=>{
            return item?.render?.(item);
        },
        onVisibleRectChange (rect) {
            let element = scrollRef?.current;
            if (element) {
                element.scrollLeft = rect.x;
                element.scrollTop = rect.y;
            }
        },
        persistedKeys: persistedKeys,
        layoutOptions: (0, $68boB$react.useMemo)(()=>{
            if (layoutOptions && layoutOptions2) return {
                ...layoutOptions,
                ...layoutOptions2
            };
            return layoutOptions || layoutOptions2;
        }, [
            layoutOptions,
            layoutOptions2
        ])
    });
    let { contentProps: contentProps } = (0, $68boB$reactariaprivatevirtualizerScrollView.useScrollView)({
        onVisibleRectChange: state.setVisibleRect,
        contentSize: state.contentSize,
        onScrollStart: state.startScrolling,
        onScrollEnd: state.endScrolling
    }, scrollRef);
    return /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement("div", contentProps, /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement($fd02a37bc042f4f4$var$VirtualizerContext.Provider, {
        value: state
    }, $fd02a37bc042f4f4$var$renderChildren(null, state.visibleViews, renderDropIndicator)));
}
function $fd02a37bc042f4f4$var$CollectionBranch({ parent: parent, renderDropIndicator: renderDropIndicator }) {
    let virtualizer = (0, $68boB$react.useContext)($fd02a37bc042f4f4$var$VirtualizerContext);
    let parentView = virtualizer.virtualizer.getVisibleView(parent.key);
    return $fd02a37bc042f4f4$var$renderChildren(parentView, Array.from(parentView.children), renderDropIndicator);
}
function $fd02a37bc042f4f4$var$renderChildren(parent, children, renderDropIndicator) {
    return children.map((view)=>$fd02a37bc042f4f4$var$renderWrapper(parent, view, renderDropIndicator));
}
function $fd02a37bc042f4f4$var$renderWrapper(parent, reusableView, renderDropIndicator) {
    let rendered = /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement((0, $68boB$reactariaprivatevirtualizerVirtualizerItem.VirtualizerItem), {
        key: reusableView.key,
        layoutInfo: reusableView.layoutInfo,
        virtualizer: reusableView.virtualizer,
        parent: parent?.layoutInfo
    }, reusableView.rendered);
    let { collection: collection, layout: layout } = reusableView.virtualizer;
    let node = reusableView.content;
    if (node?.type === 'item' && renderDropIndicator && layout.getDropTargetLayoutInfo) rendered = /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement((0, ($parcel$interopDefault($68boB$react))).Fragment, {
        key: reusableView.key
    }, $fd02a37bc042f4f4$var$renderDropIndicatorWrapper(parent, reusableView, {
        type: 'item',
        key: reusableView.content.key,
        dropPosition: 'before'
    }, renderDropIndicator), rendered, (0, $f7b82bedbb70abac$exports.renderAfterDropIndicators)(collection, node, (target)=>$fd02a37bc042f4f4$var$renderDropIndicatorWrapper(parent, reusableView, target, renderDropIndicator)));
    return rendered;
}
function $fd02a37bc042f4f4$var$renderDropIndicatorWrapper(parent, reusableView, target, renderDropIndicator) {
    let indicator = renderDropIndicator(target);
    if (indicator) {
        let layoutInfo = reusableView.virtualizer.layout.getDropTargetLayoutInfo(target);
        indicator = /*#__PURE__*/ (0, ($parcel$interopDefault($68boB$react))).createElement((0, $68boB$reactariaprivatevirtualizerVirtualizerItem.VirtualizerItem), {
            layoutInfo: layoutInfo,
            virtualizer: reusableView.virtualizer,
            parent: parent?.layoutInfo
        }, indicator);
    }
    return indicator;
}


//# sourceMappingURL=Virtualizer.cjs.map
