"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.MemberCardItem = void 0;
const contexts_1 = require("../../../../contexts/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importDefault(require("react"));
const react_i18next_1 = require("react-i18next");
const BEButton_1 = __importDefault(require("../../../generic/BEButton"));
const Icon_1 = require("../../../generic/Icon/Icon");
const Pill_1 = __importStar(require("../../../generic/Pill"));
const Text_1 = __importStar(require("../../../generic/Text"));
const RoomstayThemeEngine_1 = __importDefault(require("../../../../providers/RoomstayThemeEngine"));
const Translation_1 = require("../../../../translations/Translation");
const Color_1 = require("../../../../util/Color");
const PaymentCardHelper_1 = require("../../../../util/PaymentCardHelper");
const MemberCardItem_module_scss_1 = __importDefault(require("./MemberCardItem.module.scss"));
const MemberCardItem = (props) => {
    var _a, _b, _c, _d;
    const { item, onClick, selected } = props;
    const { roomstayMember } = react_1.default.useContext(contexts_1.RoomstayMemberContext);
    const { t } = (0, react_i18next_1.useTranslation)();
    const cardClasses = (0, classnames_1.default)(MemberCardItem_module_scss_1.default['card'], {
        [MemberCardItem_module_scss_1.default['--selected']]: selected,
    });
    const cardGraphics = (0, PaymentCardHelper_1.mapCardTypeToGraphic)(item === null || item === void 0 ? void 0 : item.type);
    const iconUrl = cardGraphics.miniCardUrl;
    const hiddenCardNumber = (_a = item === null || item === void 0 ? void 0 : item.cardNumber) === null || _a === void 0 ? void 0 : _a.substring(((_b = item === null || item === void 0 ? void 0 : item.cardNumber) === null || _b === void 0 ? void 0 : _b.length) - 4);
    const renderedIcon = iconUrl ? react_1.default.createElement("img", { src: iconUrl, alt: item === null || item === void 0 ? void 0 : item.type }) : react_1.default.createElement("img", { src: RoomstayThemeEngine_1.default.getImageAssetUrl() + 'add-card.svg', alt: "Add card" });
    const expirationDate = ((_c = item === null || item === void 0 ? void 0 : item.expiry) === null || _c === void 0 ? void 0 : _c.substring(0, 2)) + ' / ' + ((_d = item === null || item === void 0 ? void 0 : item.expiry) === null || _d === void 0 ? void 0 : _d.substring(2));
    return (react_1.default.createElement("div", { className: cardClasses, onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick() },
        react_1.default.createElement("div", { className: MemberCardItem_module_scss_1.default['card-infographic'] }, renderedIcon),
        react_1.default.createElement("div", { className: MemberCardItem_module_scss_1.default['card-details'] }, item ? (react_1.default.createElement(react_1.default.Fragment, null,
            (roomstayMember === null || roomstayMember === void 0 ? void 0 : roomstayMember.defaultCard) === item.cardId && (react_1.default.createElement("div", { className: "u-marg-bottom--light" },
                react_1.default.createElement(Pill_1.default, { size: "small", type: Pill_1.PillType.Primary }, t(Translation_1.Translation.UserPortal.PaymentInformationScreen.DefaultCard)))),
            react_1.default.createElement(Text_1.default, { bold: true, type: Text_1.TextType.Small },
                "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 ",
                hiddenCardNumber),
            react_1.default.createElement(Text_1.default, { bold: true, type: Text_1.TextType.Small }, expirationDate))) : (react_1.default.createElement(BEButton_1.default, { onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(), isText: true, textColor: Color_1.Color.Accent3, size: "tiny", icon: Icon_1.IconType.ArrowRight, iconPosition: "right" }, t(Translation_1.Translation.UserPortal.PaymentInformationScreen.AddNewCard))))));
};
exports.MemberCardItem = MemberCardItem;
//# sourceMappingURL=MemberCardItem.js.map