var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../../carousel/carousel.abstract.controller"], function (require, exports, carousel_abstract_controller_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WidgetProductsController = /** @class */ (function (_super) {
        __extends(WidgetProductsController, _super);
        function WidgetProductsController(WidgetsProductsService, $timeout, $element) {
            var _this = _super.call(this, $element) || this;
            _this.WidgetsProductsService = WidgetsProductsService;
            _this.$timeout = $timeout;
            _this.$element = $element;
            _this.products = [];
            console.log($element);
            return _this;
        }
        Object.defineProperty(WidgetProductsController.prototype, "entityIds", {
            get: function () {
                if (!this.staticEntityIds) {
                    return this.$element[0].parentNode.getAttribute('entity-ids');
                }
                else {
                    return this.staticEntityIds;
                }
            },
            set: function (entityIds) {
                this.staticEntityIds = entityIds;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WidgetProductsController.prototype, "headline", {
            get: function () {
                if (!this.staticHeadline) {
                    return this.$element[0].parentNode.getAttribute('headline');
                }
                else {
                    return this.staticHeadline;
                }
            },
            set: function (headline) {
                this.staticHeadline = headline;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WidgetProductsController.prototype, "itemsPerPage", {
            get: function () {
                if (!this.staticItemsPerPage) {
                    return parseInt(this.$element[0].parentNode.getAttribute('items-per-page'), 10);
                }
                else {
                    return this.staticItemsPerPage;
                }
            },
            set: function (itemsPerPage) {
                this.staticItemsPerPage = parseInt(itemsPerPage, 10);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WidgetProductsController.prototype, "slides", {
            get: function () {
                var numSlides = Math.ceil(this.products.length / this.itemsPerPage);
                return new Array(numSlides);
            },
            enumerable: true,
            configurable: true
        });
        WidgetProductsController.prototype.itemsHelper = function (index) {
            if (this.products.length) {
                var numShould = new Array(this.itemsPerPage);
                var offsetted = this.products.slice(index * this.itemsPerPage);
                if (numShould.length <= offsetted.length) {
                    return numShould;
                }
                else {
                    return offsetted;
                }
            }
            else {
                return [];
            }
        };
        WidgetProductsController.prototype.$onInit = function () {
            var _this = this;
            _super.prototype.$onInit.call(this);
            if (this.url) {
                this.WidgetsProductsService.setUrl(this.url);
            }
            this.WidgetsProductsService.get(this.entityIds).then(function (response) {
                if (response.status === 200) {
                    _this.$timeout(function () {
                        _this.products = response.data.items;
                    }, 0);
                }
            });
        };
        return WidgetProductsController;
    }(carousel_abstract_controller_1.CarouselAbstractController));
    exports.WidgetProductsController = WidgetProductsController;
});
//# sourceMappingURL=widget.products.controller.js.map