"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const web_1 = require("@planpay/web");
const core_1 = require("@roomstay/core");
const dayjs_1 = __importDefault(require("dayjs"));
const react_1 = require("react");
const contexts_1 = require("../contexts");
const CurrentHotelHook_1 = require("./CurrentHotelHook");
let planpaySdkLoaded = false;
const loadPlanpayOnce = (environment = 'prod') => {
    if (planpaySdkLoaded)
        return;
    web_1.planpay.init({
        environment,
        showDebug: false,
    });
    planpaySdkLoaded = true;
};
const usePlanpay = () => {
    var _a;
    const { hotel } = (0, CurrentHotelHook_1.useCurrentHotel)();
    const ccx = (0, react_1.useContext)(contexts_1.CompanyContext);
    const hasPlanpay = !!(((_a = hotel === null || hotel === void 0 ? void 0 : hotel.paymentMethods) === null || _a === void 0 ? void 0 : _a.includes(core_1.EBookingPaymentMethod.Planpay)) && hotel.planpay);
    const planpayConfig = hasPlanpay ? hotel.planpay : undefined;
    const shouldShowPlanpay = (startDate) => {
        return planpayConfig && planpayConfig.minDaysShowPlanpay && (0, dayjs_1.default)(startDate).diff((0, dayjs_1.default)(), 'day') > planpayConfig.minDaysShowPlanpay;
    };
    return {
        hasPricePreview: hasPlanpay ? ccx.currentCurrency === 'AUD' : undefined,
        hasPlanpay,
        planpay: web_1.planpay,
        planpayConfig,
        shouldShowPlanpay,
        loadPlanPaySDK: () => {
            var _a;
            loadPlanpayOnce((_a = hotel === null || hotel === void 0 ? void 0 : hotel.planpay) === null || _a === void 0 ? void 0 : _a.env);
        },
    };
};
exports.default = usePlanpay;
//# sourceMappingURL=Planpay.js.map