"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 hooks_1 = require("../../hooks/index.js");
const react_wrapper_1 = require("@googlemaps/react-wrapper");
const react_1 = __importStar(require("react"));
const Icon_1 = __importStar(require("../generic/Icon/Icon"));
const SmallSpinner_1 = __importDefault(require("../generic/loader/SmallSpinner"));
const SimpleModal_1 = __importStar(require("../generic/modal/SimpleModal"));
const RoomstayThemeEngine_1 = __importDefault(require("../../providers/RoomstayThemeEngine"));
function BEMapWidget({ mapLatLng, isFullScreen }) {
    const ref = (0, react_1.useRef)(null);
    const [map, setMap] = (0, react_1.useState)();
    const mapStyle = [
        {
            featureType: 'poi.business',
            stylers: [{ visibility: 'off' }],
        },
    ];
    (0, react_1.useEffect)(() => {
        if (ref.current) {
            const map = new window.google.maps.Map(ref.current, {
                center: mapLatLng,
                zoom: 15,
                styles: mapStyle,
            });
            setMap(map);
        }
    }, [mapLatLng]);
    (0, react_1.useEffect)(() => {
        new google.maps.Marker({
            position: mapLatLng,
            map,
        });
    }, [map, mapLatLng]);
    return (react_1.default.createElement("div", { ref: ref, id: "map", style: isFullScreen
            ? {
                height: '100%',
            }
            : undefined }));
}
function WrappedBEMapWidget(props) {
    const render = (status) => {
        switch (status) {
            case react_wrapper_1.Status.LOADING:
                return react_1.default.createElement(SmallSpinner_1.default, null);
            case react_wrapper_1.Status.FAILURE:
                return react_1.default.createElement(react_1.default.Fragment, null);
            case react_wrapper_1.Status.SUCCESS:
                return react_1.default.createElement(BEMapWidget, Object.assign({}, props));
        }
    };
    return react_1.default.createElement(react_wrapper_1.Wrapper, { apiKey: "AIzaSyBFoDziXY56EWFYGsREjZtK9fOdav2adcY", render: render });
}
exports.default = (0, react_1.forwardRef)(function BEMap(props, ref) {
    const { hotel } = (0, hooks_1.useCurrentHotel)();
    const [toggler, setToggler] = (0, react_1.useState)(false);
    const togglerOn = () => {
        return setToggler(true);
    };
    const togglerOff = () => {
        return setToggler(false);
    };
    const mapObject = (hotel === null || hotel === void 0 ? void 0 : hotel.googleMapsImage) ? react_1.default.createElement("img", { className: "static-image", src: RoomstayThemeEngine_1.default.wrapAssetUrl(hotel === null || hotel === void 0 ? void 0 : hotel.googleMapsImage) }) : react_1.default.createElement(WrappedBEMapWidget, Object.assign({}, props));
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { className: "be-map-widget" },
            react_1.default.createElement("span", { className: "room-gallery-slider__icon-lightbox-map", onClick: togglerOn },
                react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Fullscreen, size: "24px" })),
            mapObject),
        react_1.default.createElement(SimpleModal_1.default, { open: toggler, size: SimpleModal_1.SimpleModalSize.Normal, alignCenter: true, onClose: togglerOff },
            react_1.default.createElement("div", { style: { height: 500, maxHeight: '80vh' } },
                react_1.default.createElement(WrappedBEMapWidget, Object.assign({}, props, { isFullScreen: true }))))));
});
//# sourceMappingURL=BEMapWidget.js.map