"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlanpayPrice = void 0;
const contexts_1 = require("../../../contexts/index.js");
const hooks_1 = require("../../../hooks/index.js");
const web_1 = require("@planpay/web");
const react_1 = __importStar(require("react"));
const Planpay_1 = __importDefault(require("../../../hooks/Planpay"));
const PlanPayPricePreviewFeature_1 = __importDefault(require("../../../providers/feature/PlanPayPricePreviewFeature"));
const Debounce_1 = require("../../../util/Debounce");
const debounceReload = (0, Debounce_1.debounce)(() => {
    web_1.planpay.pricePreview.refresh({});
}, 150);
const PlanpayPrice = ({ price, checkin, currency }) => {
    var _a, _b, _c;
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const { hasPlanpay, loadPlanPaySDK, shouldShowPlanpay } = (0, Planpay_1.default)();
    const { selectedBasketRow } = (0, react_1.useContext)(contexts_1.BasketContext);
    (0, react_1.useEffect)(() => {
        if (hasPlanpay) {
            loadPlanPaySDK();
        }
    }, [hasPlanpay]);
    (0, react_1.useEffect)(() => {
        if (hasPlanpay) {
            debounceReload();
        }
    }, [price, currency, checkin]);
    if (!PlanPayPricePreviewFeature_1.default.isActive())
        return null;
    if (!(hotel === null || hotel === void 0 ? void 0 : hotel.planpay))
        return null;
    if (!shouldShowPlanpay((_b = (_a = selectedBasketRow === null || selectedBasketRow === void 0 ? void 0 : selectedBasketRow.getStartDate()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''))
        return null;
    return (react_1.default.createElement("div", { style: { whiteSpace: 'nowrap', marginRight: -16, marginTop: -10, marginBottom: -8, marginLeft: -12 }, "data-planpay-data-type": "price-preview", "data-planpay-total-cost": price, "data-planpay-currency-code": currency, "data-planpay-redemption-date": checkin, "data-planpay-payment-deadline": "0", "data-planpay-total-minimum-deposit": "0", "data-planpay-merchant-id": (_c = hotel === null || hotel === void 0 ? void 0 : hotel.planpay) === null || _c === void 0 ? void 0 : _c.username, "data-planpay-size": "x-small", "data-planpay-variant": "text" }));
};
exports.PlanpayPrice = PlanpayPrice;
//# sourceMappingURL=PlanpayPrice.js.map