"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.PlanpayPaymentMethod = void 0;
const contexts_1 = require("../../../contexts/index.js");
const web_1 = require("@planpay/web");
const react_1 = __importStar(require("react"));
const Placeholder_1 = __importDefault(require("../../generic/Placeholder"));
const CurrentHotelHook_1 = require("../../../hooks/CurrentHotelHook");
const Planpay_1 = __importDefault(require("../../../hooks/Planpay"));
const PlanpayWidgetLoader = () => {
    return (react_1.default.createElement("div", null,
        react_1.default.createElement("div", { className: "row no-gutters" },
            react_1.default.createElement("div", { className: "col-md-4" },
                react_1.default.createElement("div", { className: "d-flex justify-content-center" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "md", h: "sm", blink: true })),
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "md", blink: true }),
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "md", blink: true })),
            react_1.default.createElement("div", { className: "col-md-4" },
                react_1.default.createElement("div", { className: "d-flex justify-content-center" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "md", h: "sm", blink: true })),
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "sm", blink: true }),
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "sm", blink: true }),
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "sm", blink: true })),
            react_1.default.createElement("div", { className: "col-md-4" },
                react_1.default.createElement("div", { className: "d-flex justify-content-center" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "md", h: "sm", blink: true })),
                react_1.default.createElement("div", { className: "d-flex justify-content-center u-marg-top u-marg-bottom" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "xs", h: "sm", blink: true, noMarg: true })),
                react_1.default.createElement("div", { className: "d-flex justify-content-center" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "md", h: "sm", blink: true, noMarg: true })),
                react_1.default.createElement("div", { className: "d-flex justify-content-center u-marg-top u-marg-bottom" },
                    react_1.default.createElement(Placeholder_1.default, { type: "text", w: "xs", h: "sm", blink: true, noMarg: true })))),
        react_1.default.createElement("div", { className: "row no-gutters" },
            react_1.default.createElement("div", { className: "col-md-4" },
                react_1.default.createElement(Placeholder_1.default, { type: "text", h: "lg", blink: true })),
            react_1.default.createElement("div", { className: "offset-md-4 col-md-4 d-flex align-items-center" },
                react_1.default.createElement(Placeholder_1.default, { type: "text", w: "xl", h: "sm", blink: true })))));
};
const PlanpayPaymentMethod = () => {
    var _a, _b;
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const { hotel } = (0, CurrentHotelHook_1.useCurrentHotel)();
    const { hasPlanpay, loadPlanPaySDK } = (0, Planpay_1.default)();
    const planPayCheckoutResponse = (_b = (_a = basketContext.reservationData) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.planpay;
    (0, react_1.useLayoutEffect)(() => {
        if (planPayCheckoutResponse === null || planPayCheckoutResponse === void 0 ? void 0 : planPayCheckoutResponse.id) {
            web_1.planpay.checkout.refresh();
        }
    }, [planPayCheckoutResponse === null || planPayCheckoutResponse === void 0 ? void 0 : planPayCheckoutResponse.id]);
    (0, react_1.useEffect)(() => {
        if (hasPlanpay) {
            loadPlanPaySDK();
        }
    }, [hotel, hasPlanpay]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { className: "planpay-payment-container", "data-planpay-checkout-id": planPayCheckoutResponse === null || planPayCheckoutResponse === void 0 ? void 0 : planPayCheckoutResponse.id, style: { minHeight: '204px', display: 'flex', justifyContent: 'flex-end', flexDirection: 'column' } },
            react_1.default.createElement(PlanpayWidgetLoader, null))));
};
exports.PlanpayPaymentMethod = PlanpayPaymentMethod;
//# sourceMappingURL=PlanpayPaymentMethod.js.map