"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchPopup = void 0;
exports.renderSearchPopup = renderSearchPopup;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const uikit_1 = require("@gravity-ui/uikit");
const classname_1 = require("../../../classname.js");
const use_search_1 = require("../hooks/use-search.js");
const qa_1 = require("../qa.js");
const SearchCardView_1 = require("./SearchCardView.js");
const SearchCompactView_1 = require("./SearchCompactView.js");
const useObserveIntersection_1 = require("./hooks/useObserveIntersection.js");
require("./SearchPopup.css");
const b = (0, classname_1.cn)('search-popup');
const SearchPopup = ({ open, anchor, counter, onClose, intersectionTracking, ...props }) => {
    const { isCompact, searchState, handlers } = (0, use_search_1.useSearch)(props);
    const floatingRef = (0, react_1.useRef)(null);
    const { intersection } = (0, useObserveIntersection_1.useObserveIntersection)({
        floatingRef,
        container: intersectionTracking.container,
        selector: intersectionTracking.selector,
        observerOptions: intersectionTracking.observerOptions,
    });
    return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { open: open, qa: qa_1.SearchQA.Panel, anchorElement: anchor, placement: "bottom-end", floatingRef: floatingRef, floatingStyles: { opacity: intersection ? 0.8 : 1 }, className: b({ compact: isCompact }), onOpenChange: (_open, _event, reason) => {
            if (reason === 'escape-key') {
                onClose();
            }
        }, children: isCompact ? ((0, jsx_runtime_1.jsx)(SearchCompactView_1.SeachCompactView, { counter: counter, onClose: onClose, value: searchState.search, onExpand: handlers.onExpand, onChange: handlers.onSearchChange, onFindNext: handlers.onFindNext, onFindPrevious: handlers.onFindPrevious })) : ((0, jsx_runtime_1.jsx)(SearchCardView_1.SearchCardView, { counter: counter, onClose: onClose, searchState: searchState, onSearchChange: handlers.onSearchChange, onReplacementChange: handlers.onReplaceChange, onFindNext: handlers.onFindNext, onFindPrevious: handlers.onFindPrevious, onReplace: handlers.onReplace, onReplaceAll: handlers.onReplaceAll, onWholeWordChange: handlers.onWholeWordChange, onCaseSensitiveChange: handlers.onCaseSensitiveChange })) }));
};
exports.SearchPopup = SearchPopup;
exports.SearchPopup.displayName = 'SearchPopup';
function renderSearchPopup({ anchor, ...props }) {
    if (!anchor)
        return null;
    return (0, jsx_runtime_1.jsx)(exports.SearchPopup, { anchor: anchor, ...props });
}
//# sourceMappingURL=SearchPopup.js.map
