import { jsx as _jsx } from "react/jsx-runtime";
import { useRef, useEffect, memo } from 'react';
import css from './DoctorCard.module.scss';
import DoctorCard from './DoctorCard';
import { _cx } from 'src/utility/class';
import { hasDynamicProgram } from 'src/lib/common/helpers';
var cx = _cx(css);
var ResultItem = memo(function ResultItem(_a) {
    var item = _a.item, needMarkerRef = _a.needMarkerRef, markerIndex = _a.markerIndex, elRef = _a.elRef, setMarkerIndex = _a.setMarkerIndex, mapView = _a.mapView, clickedMarkerId = _a.clickedMarkerId, scrollToDocId = _a.scrollToDocId, isMobile = _a.isMobile;
    var cardRef = useRef(null);
    useEffect(function () {
        var _a;
        if (scrollToDocId === item.DocID) {
            if (!mapView) {
                var offsetEl = document.querySelector("[data-anchor=\"stickyHeader\"");
                var nav = document.querySelector('#header');
                var offsetNav = offsetEl
                    ? nav
                        ? nav.clientHeight + offsetEl.getBoundingClientRect().height + 15
                        : offsetEl.getBoundingClientRect().height + 15
                    : 0;
                var rect = (_a = cardRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
                if (rect) {
                    var y = rect.top + window.scrollY - offsetNav;
                    window.scrollTo({ top: y, behavior: 'smooth' });
                }
            }
        }
    }, [scrollToDocId, item.DocID]);
    return (_jsx("div", { className: "doctor-card-selector ".concat(cx('result-item-container', {
            mapView: mapView,
        })), ref: elRef, "data-is-heartland-ols": item.IsHeartLandOLS, "data-is-hfd-prequal": hasDynamicProgram(item, 'is_hfd_prequal'), "data-doc-id": item.DocID, children: _jsx("div", { ref: cardRef, children: _jsx(DoctorCard, { item: item, needMarkerRef: needMarkerRef, markerIndex: markerIndex, setMarkerIndex: setMarkerIndex, mapView: mapView, isMobile: isMobile, clickedMarkerId: clickedMarkerId }) }) }));
});
export default ResultItem;
