"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.UserSearchSummaryPromocodeInput = void 0;
const hooks_1 = require("../../../../hooks/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const PromoCodeInput_1 = __importDefault(require("../../../generic/PromoCodeInput"));
const Tooltip_1 = __importDefault(require("../../../generic/Tooltip/Tooltip"));
const BasketRow_1 = require("../../../../models/BasketRow");
const Translation_1 = require("../../../../translations/Translation");
const Color_1 = require("../../../../util/Color");
const UserSearchSummaryRow_module_scss_1 = __importDefault(require("./UserSearchSummaryRow.module.scss"));
const UserSearchSummaryPromocodeInput = ({ row, disabled = false, onChange, promocodeTextColor = Color_1.Color.Navy, useUpdatedDesign = false, }) => {
    const { t } = (0, react_i18next_1.useTranslation)();
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const promoCodeTooltip = (row === null || row === void 0 ? void 0 : row.getPromoCodeTooltip(t, Translation_1.Translation)) || '';
    const thisElement = (0, react_1.useRef)(null);
    const _onChangePromoCode = (code) => {
        onChange(code);
    };
    const promoCode = (0, react_1.useMemo)(() => {
        if (!row)
            return '';
        if (!hotel)
            return '';
        if (hotel.memberOnlyPromoCode === row.getPromoCode())
            return '';
        return row.getPromoCode();
    }, [row, hotel]);
    promocodeTextColor = promoCode ? row.getPromoCodeColour() : promocodeTextColor;
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(Tooltip_1.default, { title: promoCodeTooltip, wrapperClasses: "u-w-100@xl- d-flex", disabled: disabled },
            react_1.default.createElement("div", { className: (0, classnames_1.default)('u-cursor-pointer', { '--updated': useUpdatedDesign }), ref: thisElement, style: { width: '100%' } },
                react_1.default.createElement("div", { className: "u-flex align-items-center justify-content-center u-w-100@xl- room-builder-progress--promo", style: { width: '100%' } },
                    react_1.default.createElement("div", { style: { width: '100%' } },
                        react_1.default.createElement("div", { className: UserSearchSummaryRow_module_scss_1.default['user-search-summary-card-label'] }, t(Translation_1.Translation.Step.Date.PromoCode)),
                        react_1.default.createElement(PromoCodeInput_1.default, { value: promoCode, onChange: _onChangePromoCode, valid: (row === null || row === void 0 ? void 0 : row.getPromoCodeStatus()) !== BasketRow_1.EPromoCodeStatus.New ? (row === null || row === void 0 ? void 0 : row.getPromoCodeStatus()) === BasketRow_1.EPromoCodeStatus.Valid : undefined, variant: "text", hideValidText: true, row: row })))))));
};
exports.UserSearchSummaryPromocodeInput = UserSearchSummaryPromocodeInput;
//# sourceMappingURL=UserSearchSummaryPromocodeInput.js.map