"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 });
const react_1 = __importDefault(require("react"));
const react_hook_form_1 = require("react-hook-form");
const react_i18next_1 = require("react-i18next");
const InlinePaymentCard_1 = __importDefault(require("./InlinePaymentCard"));
const Pill_1 = __importStar(require("../Pill"));
const Text_1 = __importStar(require("../Text"));
const AcceptablePaymentCard_1 = __importDefault(require("../../steps/confirmation/PaymentDetails/AcceptablePaymentCard"));
const contexts_1 = require("../../../contexts");
const Currency_1 = __importDefault(require("../../../hooks/Currency"));
const Translation_1 = require("../../../translations/Translation");
const Color_1 = require("../../../util/Color");
const TextAlignment_1 = require("../../../util/TextAlignment");
const InlinePaymentOption_module_scss_1 = __importDefault(require("./InlinePaymentOption.module.scss"));
const InlinePaymentOption = ({ card, active, overrideSubLabel }) => {
    var _a;
    const { t } = (0, react_i18next_1.useTranslation)();
    const { roomstayMember } = (0, contexts_1.useMemberContext)();
    const displayExpiry = (expiry) => {
        return expiry.slice(0, 2) + ' / ' + expiry.slice(2);
    };
    const { getTotalPayNow } = (0, contexts_1.useBasket)();
    const totalPayNowBeforeGiftCard = getTotalPayNow();
    const formContext = (0, react_hook_form_1.useFormContext)();
    const giftCardAmount = (_a = formContext === null || formContext === void 0 ? void 0 : formContext.watch('giftCardAmount')) !== null && _a !== void 0 ? _a : 0;
    const totalPayNow = totalPayNowBeforeGiftCard !== null ? Math.max(0, totalPayNowBeforeGiftCard - giftCardAmount) : null;
    const { symbol, prettyValue } = (0, Currency_1.default)({
        children: totalPayNow,
    });
    const subLabel = overrideSubLabel ? overrideSubLabel : card ? `Expires ${displayExpiry(card.expiry)}` : t(Translation_1.Translation.Step.Confirmation.CardSubLabel);
    return (react_1.default.createElement("div", { className: "u-flex u-flex-justify-between w-100 u-flex-align-center" },
        react_1.default.createElement("div", { className: InlinePaymentOption_module_scss_1.default.root },
            card ? (react_1.default.createElement("div", { className: "flex-shrink-0" },
                react_1.default.createElement(InlinePaymentCard_1.default, { vgsCardName: card.type, large: true }))) : null,
            react_1.default.createElement("div", null,
                react_1.default.createElement(Text_1.default, { align: TextAlignment_1.TextAlign.Left, type: Text_1.TextType.Small, color: Color_1.Color.Navy }, card ? `**** **** **** ${card.cardNumber.slice(-4)}` : t(Translation_1.Translation.Step.Confirmation.CardLabel)),
                react_1.default.createElement(Text_1.default, { className: "u-marg-top--lighter", align: TextAlignment_1.TextAlign.Left, type: Text_1.TextType.Caption, color: Color_1.Color.DarkGrey }, subLabel)),
            !card && (react_1.default.createElement("div", null,
                react_1.default.createElement(AcceptablePaymentCard_1.default, { style: {
                        width: 24,
                        height: 16,
                        borderRadius: 1.5,
                        border: '0.5px solid #DFE1E5',
                    }, isCurrent: () => true }))),
            (roomstayMember === null || roomstayMember === void 0 ? void 0 : roomstayMember.defaultCard) && card && card.cardId === roomstayMember.defaultCard && (react_1.default.createElement(Pill_1.default, { size: "small", type: Pill_1.PillType.Primary }, "DEFAULT CARD"))),
        totalPayNow !== null && (react_1.default.createElement(Text_1.default, { bold: true, className: "u-flex", color: Color_1.Color.Navy, type: Text_1.TextType.Small },
            symbol,
            prettyValue))));
};
exports.default = InlinePaymentOption;
//# sourceMappingURL=InlinePaymentOption.js.map