"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.default = TransportDistanceFromHotelBlock;
const contexts_1 = require("../../contexts/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const Distance_1 = __importDefault(require("../generic/Distance"));
const Icon_1 = __importStar(require("../generic/Icon/Icon"));
const Text_1 = __importStar(require("../generic/Text"));
const Translation_1 = require("../../translations/Translation");
const Color_1 = require("../../util/Color");
const TextAlignment_1 = require("../../util/TextAlignment");
const TransportDistanceFromHotelBlock_module_scss_1 = __importDefault(require("./TransportDistanceFromHotelBlock.module.scss"));
function TransportDistanceFromHotelBlock(props) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    const { transportDistances } = (0, react_1.useContext)(contexts_1.HotelOverridesContext);
    const { vertical, tightMargins } = props;
    const { t } = (0, react_i18next_1.useTranslation)();
    const distanceValues = [
        {
            icon: Icon_1.IconType.Airplane,
            name: t(Translation_1.Translation.TransportDistances.Airport),
            distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.plane,
            configuration: ((_a = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _a === void 0 ? void 0 : _a.plane) || {},
        },
        { icon: Icon_1.IconType.Train, name: t(Translation_1.Translation.TransportDistances.Train), distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.train, configuration: ((_b = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _b === void 0 ? void 0 : _b.train) || {} },
        { icon: Icon_1.IconType.Train, name: t(Translation_1.Translation.TransportDistances.Tram), distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.tram, configuration: ((_c = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _c === void 0 ? void 0 : _c.tram) || {} },
        { icon: Icon_1.IconType.Bus, name: t(Translation_1.Translation.TransportDistances.Bus), distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.bus, configuration: ((_d = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _d === void 0 ? void 0 : _d.bus) || {} },
        { icon: Icon_1.IconType.Taxi, name: t(Translation_1.Translation.TransportDistances.Taxi), distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.taxi, configuration: ((_e = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _e === void 0 ? void 0 : _e.taxi) || {} },
        {
            icon: Icon_1.IconType.Ferry,
            name: t(Translation_1.Translation.TransportDistances.Ferry),
            distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.ferry,
            configuration: ((_f = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _f === void 0 ? void 0 : _f.ferry) || {},
        },
        {
            icon: Icon_1.IconType.Location,
            name: t(Translation_1.Translation.TransportDistances.Location),
            distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.location,
            configuration: ((_g = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _g === void 0 ? void 0 : _g.location) || {},
        },
        {
            icon: Icon_1.IconType.Car,
            name: t(Translation_1.Translation.TransportDistances.Car),
            distance: transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.car,
            configuration: ((_h = transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.configuration) === null || _h === void 0 ? void 0 : _h.car) || {},
        },
    ].filter(({ distance }) => !!distance);
    const tightMarginClass = tightMargins ? 'u-marg-left-right' : 'u-marg-left-right--heavy';
    return (transportDistances === null || transportDistances === void 0 ? void 0 : transportDistances.displayCard) ? (react_1.default.createElement("div", { className: (0, classnames_1.default)(TransportDistanceFromHotelBlock_module_scss_1.default['rs-transport-distances'], 'rs-transport-distances d-flex flex-wrap justify-content-between u-w-100') }, distanceValues.map((distanceValue, index) => (react_1.default.createElement(DistanceDisplayCard, Object.assign({ key: index }, distanceValue, { vertical: vertical, totalValues: distanceValues.length })))))) : (react_1.default.createElement(react_1.default.Fragment, null, distanceValues.map((distanceValue, index) => (react_1.default.createElement(DistanceDisplay, Object.assign({ key: index }, distanceValue, { vertical: vertical, tightMarginClass: tightMarginClass }))))));
}
const DistanceDisplayCard = ({ icon, distance, configuration: { suffix, subTitle, unit }, totalValues, vertical, }) => (react_1.default.createElement("div", { style: Object.assign({}, (!vertical && {
        minWidth: `${100 / totalValues}%`,
    })), className: "d-flex flex-row transport-card" },
    react_1.default.createElement("div", { className: (0, classnames_1.default)(TransportDistanceFromHotelBlock_module_scss_1.default['transport-card-icon'], 'transport-card-icon') },
        react_1.default.createElement(Icon_1.default, { icon: icon, size: "1.3em", color: Color_1.Color.Accent })),
    react_1.default.createElement("div", { className: "d-flex flex-column transport-card-details" },
        react_1.default.createElement(Text_1.default, { bold: true, align: TextAlignment_1.TextAlign.Left, type: vertical ? Text_1.TextType.Small : Text_1.TextType.Body, color: Color_1.Color.Accent, className: "transport-card-title" },
            react_1.default.createElement(Distance_1.default, { distance: distance, unit: unit }),
            " ", suffix !== null && suffix !== void 0 ? suffix : ''),
        react_1.default.createElement(Text_1.default, { align: TextAlignment_1.TextAlign.Left, type: vertical ? Text_1.TextType.Label : Text_1.TextType.Small, color: Color_1.Color.Graphite, className: "transport-card-subtitle" }, subTitle))));
const DistanceDisplay = ({ name, icon, distance, configuration: { unit }, vertical, tightMarginClass }) => (react_1.default.createElement("div", { className: vertical ? 'u-flex flex-column u-marg-top-bottom' : `${tightMarginClass} u-marg-left-right@l-` },
    react_1.default.createElement(Text_1.default, { align: vertical ? TextAlignment_1.TextAlign.Center : undefined, type: Text_1.TextType.Small, color: Color_1.Color.DarkGrey },
        react_1.default.createElement("strong", null, name)),
    react_1.default.createElement("div", { className: (0, classnames_1.default)('u-flex u-marg-top--light', {
            'justify-content-start flex-column align-items-center': vertical,
            'align-items-end': !vertical,
        }) },
        react_1.default.createElement(Icon_1.default, { icon: icon, size: "1.3em" }),
        react_1.default.createElement("span", { className: vertical ? 'u-marg-top--light' : 'u-marg-left--light' },
            react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small },
                react_1.default.createElement("span", { className: "u-nowrap" },
                    react_1.default.createElement(Distance_1.default, { unit: unit, distance: distance })))))));
//# sourceMappingURL=TransportDistanceFromHotelBlock.js.map