"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.trueRewardsPaymentHandler = void 0;
const core_1 = require("@roomstay/core");
const react_1 = __importDefault(require("react"));
const TrueRewardsLabel_1 = __importDefault(require("../../components/steps/confirmation/TrueRewardsPaymentOption/TrueRewardsLabel"));
const TrueRewardsPaymentMethod_1 = require("../../components/steps/confirmation/TrueRewardsPaymentOption/TrueRewardsPaymentMethod");
const hooks_1 = require("../../hooks");
const trueRewardsPaymentHandler = () => {
    var _a;
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    let firstPaymentAmount = null;
    let isApplied = false;
    return {
        name: 'TrueRewards',
        isAvailable: !!((_a = hotel === null || hotel === void 0 ? void 0 : hotel.paymentMethods) === null || _a === void 0 ? void 0 : _a.includes(core_1.EBookingPaymentMethod.TrueRewards)),
        isExclusive: false,
        requireBookingPlaced: false,
        requireFormFilled: false,
        bookingPaymentMethod: core_1.EBookingPaymentMethod.TrueRewards,
        onConfirm: () => __awaiter(void 0, void 0, void 0, function* () {
            return { success: isApplied, message: '' };
        }),
        getBookingPaymentRequestObject: () => __awaiter(void 0, void 0, void 0, function* () {
            return Object.assign({ Method: core_1.EBookingPaymentMethod.TrueRewards }, (firstPaymentAmount && { SplitPaymentAmount: firstPaymentAmount }));
        }),
        renderInput: () => react_1.default.createElement(TrueRewardsLabel_1.default, null),
        renderPaymentInput: () => (react_1.default.createElement(TrueRewardsPaymentMethod_1.TrueRewardsPaymentMethod, { onApplied: (balance, applied) => {
                firstPaymentAmount = balance;
                isApplied = applied;
            } })),
    };
};
exports.trueRewardsPaymentHandler = trueRewardsPaymentHandler;
//# sourceMappingURL=TrueRewardsPaymentHandler.js.map