"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultCardProduct = void 0;
const react_1 = __importDefault(require("react"));
const react_intersection_observer_1 = require("react-intersection-observer");
const hooks_1 = require("../../hooks");
const components_1 = require("../../components");
const ResultCardProduct = (props) => {
    var _a;
    const productPrice = (0, hooks_1.useProductPrice)(props.product);
    const { track } = (0, hooks_1.useAnalytics)();
    const { ref, inView } = (0, react_intersection_observer_1.useInView)({
        threshold: 0.5,
        triggerOnce: true,
    });
    const handleClick = react_1.default.useCallback(() => {
        track({
            eventName: "clickProduct",
            payload: {
                elasticProduct: {
                    id: props.product.id,
                    title: props.product.title,
                },
            },
        });
    }, [track, props.product]);
    const handleView = react_1.default.useCallback(() => {
        track({
            eventName: "viewProduct",
            payload: {
                elasticProduct: {
                    id: props.product.id,
                    title: props.product.title,
                },
            },
        });
    }, [track, props.product]);
    react_1.default.useEffect(() => {
        var _a;
        if (inView) {
            (_a = props.onView) === null || _a === void 0 ? void 0 : _a.call(props);
            handleView();
        }
    }, [inView]);
    const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleResultCardProduct;
    return (react_1.default.createElement(RenderComponent, Object.assign({}, productPrice, { pagePosition: props.pagePosition, product: props.product, document: props.document, itemRef: ref, handleClick: handleClick })));
};
exports.ResultCardProduct = ResultCardProduct;
//# sourceMappingURL=ResultCardProduct.js.map