import {useLocale as $4defb058003b3e05$export$43bb16f9c6d9e3f7} from "../i18n/I18nProvider.js";
import {useVirtualizerItem as $50fb5bc04a398332$export$1da781778207e0a2} from "./useVirtualizerItem.js";
import $ctdHo$react, {useRef as $ctdHo$useRef} from "react";

/*
 * Copyright 2020 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.
 */ 


function $5e03ff6b3cb668b8$export$6796df8ba7398521(props) {
    let { style: style, className: className, layoutInfo: layoutInfo, virtualizer: virtualizer, parent: parent, children: children } = props;
    let { direction: direction } = (0, $4defb058003b3e05$export$43bb16f9c6d9e3f7)();
    let ref = (0, $ctdHo$useRef)(null);
    (0, $50fb5bc04a398332$export$1da781778207e0a2)({
        layoutInfo: layoutInfo,
        virtualizer: virtualizer,
        ref: ref
    });
    return /*#__PURE__*/ (0, $ctdHo$react).createElement("div", {
        role: "presentation",
        ref: ref,
        className: className,
        style: {
            ...$5e03ff6b3cb668b8$export$1481e64fbe01b8b3(layoutInfo, direction, parent),
            ...style
        }
    }, children);
}
let $5e03ff6b3cb668b8$var$cache = new WeakMap();
function $5e03ff6b3cb668b8$export$1481e64fbe01b8b3(layoutInfo, dir, parent) {
    let xProperty = dir === 'rtl' ? 'right' : 'left';
    let cached = $5e03ff6b3cb668b8$var$cache.get(layoutInfo);
    if (cached && cached[xProperty] != null) {
        if (!parent) return cached;
        // Invalidate if the parent position changed.
        let top = layoutInfo.rect.y - parent.rect.y;
        let x = layoutInfo.rect.x - parent.rect.x;
        if (cached.top === top && cached[xProperty] === x) return cached;
    }
    let rectStyles = {
        // TODO: For layoutInfos that are sticky that have parents with overflow visible, their "top" will be relative to the to the nearest scrolling container
        // which WON'T be the parent since the parent has overflow visible. This means we shouldn't offset the height by the parent's position
        // Not 100% about this change here since it is quite ambigious what the scrolling container maybe and how its top is positioned with respect to the
        // calculated layoutInfo.y here
        top: layoutInfo.rect.y - (parent && !(parent.allowOverflow && layoutInfo.isSticky) ? parent.rect.y : 0),
        [xProperty]: layoutInfo.rect.x - (parent && !(parent.allowOverflow && layoutInfo.isSticky) ? parent.rect.x : 0),
        width: layoutInfo.rect.width,
        height: layoutInfo.rect.height
    };
    // Get rid of any non finite values since they aren't valid css values
    Object.entries(rectStyles).forEach(([key, value])=>{
        if (!Number.isFinite(value)) rectStyles[key] = undefined;
    });
    var _layoutInfo_transform;
    let style = {
        position: layoutInfo.isSticky ? 'sticky' : 'absolute',
        // Sticky elements are positioned in normal document flow. Display inline-block so that they don't push other sticky columns onto the following rows.
        display: layoutInfo.isSticky ? 'inline-block' : undefined,
        overflow: layoutInfo.allowOverflow ? 'visible' : 'hidden',
        opacity: layoutInfo.opacity,
        zIndex: layoutInfo.zIndex,
        transform: (_layoutInfo_transform = layoutInfo.transform) !== null && _layoutInfo_transform !== void 0 ? _layoutInfo_transform : undefined,
        contain: 'size layout style',
        ...rectStyles
    };
    $5e03ff6b3cb668b8$var$cache.set(layoutInfo, style);
    return style;
}


export {$5e03ff6b3cb668b8$export$6796df8ba7398521 as VirtualizerItem, $5e03ff6b3cb668b8$export$1481e64fbe01b8b3 as layoutInfoToStyle};
//# sourceMappingURL=VirtualizerItem.js.map
