define(["require", "exports", "./constants", "rx/dist/rx.all"], function (require, exports, constants_1, Rx) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SearchService = /** @class */ (function () {
        function SearchService($http, $sce) {
            this.$http = $http;
            this.$sce = $sce;
            this.subject = new Rx.BehaviorSubject(null);
        }
        SearchService.prototype.get = function () {
            return this.subject;
        };
        SearchService.prototype.updateQuery = function (query) {
            this.getData(query);
        };
        SearchService.prototype.getData = function (query, page) {
            var _this = this;
            if (page === void 0) { page = 1; }
            var fields = [
                'image',
                'title',
                'type',
                'url',
                'body'
            ];
            var url = "https://api.swiftype.com/api/v1/public/engines/search.json?q=" + query + "&engine_key=" + constants_1.SWIFTTYPE_KEY + "&page=" + page;
            for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
                var field = fields_1[_i];
                url += "&fetch_fields[page][]=" + field;
            }
            var trustedUrl = this.$sce.trustAsResourceUrl(url);
            this.$http.jsonp(trustedUrl, {
                jsonpCallbackParam: 'callback',
                cache: true
            })
                .then(function (result) {
                _this.subject.onNext(result.data);
            });
        };
        return SearchService;
    }());
    exports.SearchService = SearchService;
});
//# sourceMappingURL=search.service.js.map