"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 });
var React = require("react");
var ViewModels_1 = require("../../../../apiModels/ViewModels");
var OrderSummary = /** @class */ (function (_super) {
    __extends(OrderSummary, _super);
    function OrderSummary() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.calculateProductsPrice = function () {
            return _this.props.orderItems.reduce(function (sum, obj) { return sum + (obj.price * obj.amount); }, 0);
        };
        _this.calculateTotalPrice = function (productPrice) {
            var totalPrice = 0;
            _this.props.orderItems.forEach(function (item) {
                totalPrice += (Math.round(((item.price * item.amount) + Number.EPSILON) * 100) / 100);
            });
            totalPrice += _this.props.deliveryType.fee;
            totalPrice += _this.props.paymentType.fee;
            return productPrice >= 1000 ? totalPrice - _this.props.deliveryType.fee : totalPrice;
        };
        return _this;
    }
    OrderSummary.prototype.render = function () {
        var _a = this.props, orderItems = _a.orderItems, deliveryType = _a.deliveryType, paymentType = _a.paymentType;
        var productPrice = this.calculateProductsPrice();
        var totalPrice = this.calculateTotalPrice(productPrice);
        return (React.createElement(React.Fragment, null,
            React.createElement("h4", null, "Va\u0161e objedn\u00E1vka"),
            React.createElement("div", { className: "checkout__order__products" },
                "Produkty ",
                React.createElement("span", null, "Cena")),
            React.createElement("ul", null, orderItems.map(function (item) {
                return React.createElement("li", { key: item.productID },
                    item.name,
                    React.createElement("span", null,
                        (item.price * item.amount).toFixed(2),
                        " K\u010D"));
            })),
            React.createElement("div", { className: "checkout__order__subtotal" },
                "Produkty celkem ",
                React.createElement("span", null,
                    productPrice.toFixed(2),
                    " Kc")),
            React.createElement("ul", null,
                deliveryType !== undefined && deliveryType.id !== 0
                    ? React.createElement("li", null,
                        deliveryType.name,
                        " ",
                        React.createElement("span", null,
                            "+ ",
                            deliveryType.fee,
                            " K\u010D"))
                    : '',
                deliveryType.id == ViewModels_1.DeliveryType.Delivery && productPrice >= 1000
                    ? React.createElement("li", null,
                        deliveryType.name,
                        " (SLEVA)",
                        React.createElement("span", null,
                            "- ",
                            deliveryType.fee,
                            " K\u010D"))
                    : null,
                deliveryType !== undefined && paymentType !== undefined && deliveryType.id !== 0 && paymentType.id !== 0
                    ? React.createElement("li", null,
                        paymentType.name,
                        " ",
                        React.createElement("span", null,
                            "+ ",
                            paymentType.fee,
                            " K\u010D"))
                    : ''),
            React.createElement("div", { className: "checkout__order__total" },
                "Cena celkem ",
                React.createElement("span", null,
                    Math.round(totalPrice),
                    " K\u010D"))));
    };
    return OrderSummary;
}(React.Component));
exports.default = OrderSummary;
//# sourceMappingURL=OrderSummary.js.map