"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 axios_1 = require("axios");
var react_router_dom_1 = require("react-router-dom");
var routes_1 = require("../../../../apiClient/routes");
var OrderDetailAddresses_1 = require("./Orders/OrderDetailAddresses");
var OrderDetailHeader_1 = require("./Orders/OrderDetailHeader");
var httpService_1 = require("../../../../services/httpService");
var OrderDetail = /** @class */ (function (_super) {
    __extends(OrderDetail, _super);
    function OrderDetail() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            order: {}
        };
        return _this;
    }
    OrderDetail.prototype.componentDidMount = function () {
        var _this = this;
        var orderId = this.props.match.params.id;
        if (orderId) {
            httpService_1.default.get((0, routes_1.OrderController_GetOrderDetail)(orderId)).then(function (response) {
                var order = response.data;
                _this.setState({ order: order });
            })
                .catch(function (e) {
                console.log(e);
                // pri chybe (nenalezeni objednavky apod.), presmerovani na vypis produktu
                _this.props.history.push("/");
            });
        }
    };
    OrderDetail.prototype.render = function () {
        var order = this.state.order;
        if (order.orderItems !== undefined) {
            return (React.createElement(React.Fragment, null,
                React.createElement("section", { className: "order-detail" },
                    React.createElement("div", { className: "container" },
                        React.createElement(OrderDetailHeader_1.OrderDetailHeader, { order: order }),
                        React.createElement("div", { className: "row" },
                            React.createElement("div", { className: "col-lg-12" },
                                React.createElement("div", { className: "order__detail__table" },
                                    React.createElement("table", null,
                                        React.createElement("thead", null,
                                            React.createElement("tr", null,
                                                React.createElement("th", { className: "order__detail__item__name" }, "Produkt"),
                                                React.createElement("th", null, "Cena"),
                                                React.createElement("th", null, "Kus\u016F"),
                                                React.createElement("th", { className: "order__detail__total__price" }, "Cena celkem"))),
                                        React.createElement("tbody", null, order.orderItems.map(function (orderItem) {
                                            return React.createElement("tr", { key: "orderDetailItem-".concat(orderItem.id) },
                                                React.createElement("td", { className: "order__detail__item" },
                                                    React.createElement("img", { src: (orderItem.imageID !== undefined && orderItem.imageID !== null && orderItem.imageID !== 0)
                                                            ? "".concat(axios_1.default.defaults.baseURL + (0, routes_1.ProductImageController_GetImage)(orderItem.imageID.toString()))
                                                            : "img/cart/cart-1.jpg", width: "100px" }),
                                                    React.createElement(react_router_dom_1.Link, { to: "/product/".concat(orderItem.productID) },
                                                        React.createElement("h5", null, orderItem.name))),
                                                React.createElement("td", { className: "order__detail__price" },
                                                    orderItem.price,
                                                    " K\u010D"),
                                                React.createElement("td", null, orderItem.amount),
                                                React.createElement("td", null,
                                                    orderItem.totalPrice,
                                                    " K\u010D"));
                                        })))))),
                        React.createElement(OrderDetailAddresses_1.OrderDetailAddresses, { order: order })))));
        }
        else {
            return null;
        }
    };
    return OrderDetail;
}(React.Component));
exports.default = OrderDetail;
//# sourceMappingURL=OrderDetail.js.map