(window["webpackJsonpCoveoForSitecore"] = window["webpackJsonpCoveoForSitecore"] || []).push([["GoogleApiPositionProvider"],{

/***/ "./src/rest/EndpointCaller.ts":
/*!************************************!*\
  !*** ./src/rest/EndpointCaller.ts ***!
  \************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EndpointCallerWrapper = void 0;
var coveo_search_ui_1 = __webpack_require__(/*! coveo-search-ui */ "coveo-search-ui");
var EndpointCallerWrapper = /** @class */ (function () {
    function EndpointCallerWrapper(endpointCaller) {
        this.endpointCaller = endpointCaller || new coveo_search_ui_1.EndpointCaller();
    }
    EndpointCallerWrapper.prototype.sendPost = function (url, postData) {
        var callOptions = {
            errorsAsSuccess: false,
            method: 'POST',
            queryString: [],
            requestData: postData,
            url: url,
            responseType: 'text',
            requestDataType: 'application/json',
        };
        return this.endpointCaller.call(callOptions);
    };
    return EndpointCallerWrapper;
}());
exports.EndpointCallerWrapper = EndpointCallerWrapper;


/***/ }),

/***/ "./src/ui/distance/GoogleApiPositionProvider.ts":
/*!******************************************************!*\
  !*** ./src/ui/distance/GoogleApiPositionProvider.ts ***!
  \******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoogleApiPositionProvider = void 0;
var coveo_search_ui_1 = __webpack_require__(/*! coveo-search-ui */ "coveo-search-ui");
var EndpointCaller_1 = __webpack_require__(/*! ../../rest/EndpointCaller */ "./src/rest/EndpointCaller.ts");
var GOOGLE_MAP_BASE_URL = 'https://www.googleapis.com/geolocation/v1/geolocate';
var GoogleApiPositionProvider = exports.GoogleApiPositionProvider = /** @class */ (function (_super) {
    __extends(GoogleApiPositionProvider, _super);
    function GoogleApiPositionProvider(element, options, bindings) {
        var _this = _super.call(this, element, GoogleApiPositionProvider.ID, bindings) || this;
        _this.element = element;
        _this.options = options;
        _this.bindings = bindings;
        _this.options = coveo_search_ui_1.ComponentOptions.initComponentOptions(element, GoogleApiPositionProvider, options);
        _this.endpointCaller = new EndpointCaller_1.EndpointCallerWrapper();
        _this.bind.onRootElement(coveo_search_ui_1.DistanceEvents.onResolvingPosition, _this.onResolvingPosition);
        _this.validateProperties();
        return _this;
    }
    GoogleApiPositionProvider.prototype.onResolvingPosition = function (args) {
        var _this = this;
        if (this.canProvideDistance()) {
            args.providers.push({
                getPosition: function () { return _this.getPosition(); },
            });
        }
    };
    GoogleApiPositionProvider.prototype.canProvideDistance = function () {
        return !!this.options.googleApiKey;
    };
    GoogleApiPositionProvider.prototype.getPosition = function () {
        return this.endpointCaller
            .sendPost("".concat(GOOGLE_MAP_BASE_URL, "?key=").concat(this.options.googleApiKey), {})
            .then(function (positionData) {
            var location = positionData.data.location;
            return {
                latitude: location.lat,
                longitude: location.lng,
            };
        });
    };
    GoogleApiPositionProvider.prototype.validateProperties = function () {
        if (!this.options.googleApiKey) {
            this.logger.error("You must set the \"googleApiKey\" property for this component to work properly. It will be disabled.");
        }
    };
    GoogleApiPositionProvider.ID = 'GoogleApiPositionProvider';
    GoogleApiPositionProvider.options = {
        googleApiKey: coveo_search_ui_1.ComponentOptions.buildStringOption({
            required: true,
        }),
    };
    return GoogleApiPositionProvider;
}(coveo_search_ui_1.Component));
coveo_search_ui_1.Initialization.registerAutoCreateComponent(GoogleApiPositionProvider);


/***/ })

}]);
//# sourceMappingURL=GoogleApiPositionProvider.js.map