"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 __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var Yup = require("yup");
var CreateAccountForm_1 = require("./Checkout/CreateAccountForm");
var DeliveryAddressForm_1 = require("./Checkout/DeliveryAddressForm");
var DeliveryAndPaymentTypeForm_1 = require("./Checkout/DeliveryAndPaymentTypeForm");
var react_dropdown_1 = require("react-dropdown");
var InvoicingAddressForm_1 = require("./Checkout/InvoicingAddressForm");
var OrderSummary_1 = require("./Checkout/OrderSummary");
var routes_1 = require("../../../apiClient/routes");
var ViewModels_1 = require("../../../apiModels/ViewModels");
var formik_1 = require("formik");
var localStorageService_1 = require("../../../services/localStorageService");
var react_router_dom_1 = require("react-router-dom");
var httpService_1 = require("../../../services/httpService");
var react_toastify_1 = require("react-toastify");
var Checkout = /** @class */ (function (_super) {
    __extends(Checkout, _super);
    function Checkout() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            deliveryTypes: new Array(),
            errorMessage: '',
            filteredPaymentTypes: new Array(),
            isLoggedIn: false,
            orderItems: Array(),
            paymentTypes: new Array(),
            selectedDeliveryAddress: '',
            selectedDeliveryType: {
                id: 0,
                name: '',
                fee: 0
            },
            selectedInvoicingAddress: '',
            selectedPaymentType: {
                id: 0,
                name: '',
                fee: 0
            },
            showCreateAccountForm: false,
            showDeliveryAddressForm: false,
            showSelectPaymentType: false,
            userAddresses: Array(),
            userId: ''
        };
        _this.handleDeliveryAddressChange = function (arg) {
            _this.setState({ selectedDeliveryAddress: arg.value });
        };
        _this.handleDeliveryTypeChange = function (item) {
            if (item.name === "Vyzvednutí na prodejně") {
                var paymentTypes = _this.state.paymentTypes.filter(function (i) { return i.name !== "Dobírka"; }).sort(function (a, b) { return a.name > b.name ? 1 : -1; });
                _this.setState({ filteredPaymentTypes: paymentTypes, selectedDeliveryType: item, selectedPaymentType: paymentTypes.find(function (i) { return i.name === "Bankovní převod"; }), showSelectPaymentType: true });
            }
            else if (item.name === "Doručení námi") {
                var paymentTypes = _this.state.paymentTypes.filter(function (i) { return i.name !== "Na prodejně"; }).sort(function (a, b) { return a.name > b.name ? 1 : -1; });
                _this.setState({ filteredPaymentTypes: paymentTypes, selectedDeliveryType: item, selectedPaymentType: paymentTypes.find(function (i) { return i.name === "Bankovní převod"; }), showSelectPaymentType: true });
            }
        };
        _this.handleInvoicingAddressChange = function (arg) {
            _this.setState({ selectedInvoicingAddress: arg.value });
        };
        _this.handlePaymentTypeChange = function (item) {
            _this.setState({ selectedPaymentType: item });
        };
        _this.handleShowCreateAccountFormChange = function () {
            var showCreateAccountForm = _this.state.showCreateAccountForm;
            _this.setState({ showCreateAccountForm: !showCreateAccountForm });
        };
        _this.handleShowDeliveryAddressFormChange = function () {
            var showDeliveryAddressForm = _this.state.showDeliveryAddressForm;
            _this.setState({ showDeliveryAddressForm: !showDeliveryAddressForm, selectedDeliveryAddress: '' });
        };
        _this.handleSubmit = function (formValues) {
            var _a = _this.state, orderItems = _a.orderItems, isLoggedIn = _a.isLoggedIn, showCreateAccountForm = _a.showCreateAccountForm, showDeliveryAddressForm = _a.showDeliveryAddressForm, userId = _a.userId;
            var data = {
                userId: isLoggedIn ? userId : null,
                invoicingAddress: formValues.invoicingAddress,
                deliveryAddress: showDeliveryAddressForm ? formValues.deliveryAddress : null,
                orderItems: orderItems.map(function (i) { return { productID: i.productID, amount: i.amount }; }),
                password: showCreateAccountForm ? formValues.password : null,
                deliveryTypeID: formValues.deliveryTypePicked,
                paymentTypeID: formValues.paymentTypePicked
            };
            httpService_1.default.post(routes_1.OrderController_CreateOrder, data, { validateStatus: function (status) { return status <= 400; } }).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                var user, orderNumber, totalPrice;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (!(response.status === 200)) return [3 /*break*/, 3];
                            // smazat kosik z local storage
                            if (!isLoggedIn) {
                                (0, localStorageService_1.RemoveShoppingCartFromLocalStorage)();
                                // Problem s react state update on an unmounted component
                                //this.props.clearShoppingCart();
                            }
                            react_toastify_1.toast.success("Objedn\u00E1vka \u00FAsp\u011B\u0161n\u011B vytvo\u0159ena!", {
                                position: "top-right",
                                autoClose: 3000,
                                hideProgressBar: true,
                                closeOnClick: true,
                                pauseOnHover: false,
                                draggable: true,
                                progress: undefined,
                            });
                            user = (0, localStorageService_1.GetObject)();
                            if (user !== null) {
                                this.props.getUserShoppingCart(user);
                            }
                            return [4 /*yield*/, response.data.orderNumber];
                        case 1:
                            orderNumber = _a.sent();
                            return [4 /*yield*/, response.data.totalPrice];
                        case 2:
                            totalPrice = _a.sent();
                            //this.props.clearShoppingCart(orderNumber, totalPrice);
                            this.props.history.push("/order/successful", { orderNumber: response.data.orderNumber, totalPrice: response.data.totalPrice });
                            return [3 /*break*/, 4];
                        case 3:
                            this.setState({ errorMessage: response.data.errorMessage });
                            react_toastify_1.toast.error("".concat(response.data.errorMessage), {
                                position: "top-right",
                                autoClose: 3000,
                                hideProgressBar: true,
                                closeOnClick: true,
                                pauseOnHover: false,
                                draggable: true,
                                progress: undefined,
                            });
                            _a.label = 4;
                        case 4: return [2 /*return*/];
                    }
                });
            }); }).catch(function (e) {
                console.log(e);
                _this.setState(__assign({}, _this.state));
            });
        };
        return _this;
    }
    Checkout.prototype.componentDidMount = function () {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
        return __awaiter(this, void 0, void 0, function () {
            var user, history_1, storageOrderItems, orderItems_1;
            var _this = this;
            return __generator(this, function (_u) {
                switch (_u.label) {
                    case 0:
                        document.title = "Vytvoření objednávky";
                        return [4 /*yield*/, httpService_1.default.get(routes_1.OrderController_GetDeliveryTypes).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                                var deliveryTypes;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, response.data];
                                        case 1:
                                            deliveryTypes = _a.sent();
                                            this.setState({ deliveryTypes: deliveryTypes });
                                            return [2 /*return*/];
                                    }
                                });
                            }); })
                                .catch(function (e) {
                                console.log(e);
                                _this.setState(__assign({}, _this.state));
                            })];
                    case 1:
                        _u.sent();
                        return [4 /*yield*/, httpService_1.default.get(routes_1.OrderController_GetPaymentTypes).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                                var paymentTypes;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, response.data];
                                        case 1:
                                            paymentTypes = _a.sent();
                                            this.setState({ paymentTypes: paymentTypes });
                                            return [2 /*return*/];
                                    }
                                });
                            }); })
                                .catch(function (e) {
                                console.log(e);
                                _this.setState(__assign({}, _this.state));
                            })];
                    case 2:
                        _u.sent();
                        user = (0, localStorageService_1.GetObject)();
                        if (!(user !== null)) return [3 /*break*/, 5];
                        return [4 /*yield*/, httpService_1.default.get((0, routes_1.AddressController_GetUserAddresses)(user.unique_name.toString())).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                                var userAddresses;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, response.data];
                                        case 1:
                                            userAddresses = _a.sent();
                                            this.setState({ userAddresses: userAddresses });
                                            return [2 /*return*/];
                                    }
                                });
                            }); })];
                    case 3:
                        _u.sent();
                        return [4 /*yield*/, httpService_1.default.get((0, routes_1.OrderController_GetUserShoppingCartItems)(user.unique_name.toString())).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                                var orderItems;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, response.data];
                                        case 1:
                                            orderItems = _a.sent();
                                            orderItems.sort(function (a, b) { return a.name > b.name ? 1 : -1; });
                                            this.setState({ orderItems: orderItems, isLoggedIn: true, userId: user.unique_name });
                                            return [2 /*return*/];
                                    }
                                });
                            }); }).catch(function (e) {
                                console.log(e);
                                _this.setState(__assign({}, _this.state));
                            })];
                    case 4:
                        _u.sent();
                        // Musí být otestováno
                        // Vybirani adres prihlaseneho uzivatele
                        if (((_a = this.props.location) === null || _a === void 0 ? void 0 : _a.state) !== undefined) {
                            history_1 = this.props.location.state;
                            this.setState({
                                selectedInvoicingAddress: ((_b = history_1.invoicingAddress) === null || _b === void 0 ? void 0 : _b.id) !== undefined ? history_1.invoicingAddress.id.toString() : '',
                                selectedDeliveryAddress: ((_c = history_1.deliveryAddress) === null || _c === void 0 ? void 0 : _c.id) !== undefined ? history_1.deliveryAddress.id.toString() : ''
                            });
                        }
                        return [3 /*break*/, 7];
                    case 5:
                        storageOrderItems = (0, localStorageService_1.GetShoppingCart)();
                        if (!(storageOrderItems.length > 0)) return [3 /*break*/, 7];
                        orderItems_1 = [];
                        return [4 /*yield*/, Promise.all(storageOrderItems.map(function (i) { return __awaiter(_this, void 0, void 0, function () {
                                var _this = this;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, httpService_1.default.get((0, routes_1.ProductController_GetProduct)(i.productID.toString())).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
                                                var product, orderItem;
                                                return __generator(this, function (_a) {
                                                    switch (_a.label) {
                                                        case 0: return [4 /*yield*/, response.data];
                                                        case 1:
                                                            product = _a.sent();
                                                            orderItem = {
                                                                id: undefined,
                                                                productID: product.id,
                                                                name: product.name,
                                                                price: (product.reducedPrice !== undefined && product.reducedPrice > 0 && product.reducedPrice < product.price) ? product.reducedPrice : product.price,
                                                                amount: i.amount,
                                                                availableQuantity: product.availableQuantity,
                                                                productCategoryID: product.productCategoryID,
                                                                productCategoryName: product.productCategoryName,
                                                                productImageID: product.productImageIDs[0] // not needed
                                                            };
                                                            orderItems_1.push(orderItem);
                                                            return [2 /*return*/];
                                                    }
                                                });
                                            }); })
                                                .catch(function (e) {
                                                console.log(e);
                                                _this.setState(__assign({}, _this.state));
                                            })];
                                        case 1:
                                            _a.sent();
                                            return [2 /*return*/];
                                    }
                                });
                            }); }))];
                    case 6:
                        _u.sent();
                        orderItems_1.sort(function (a, b) { return a.name > b.name ? 1 : -1; });
                        this.setState({ orderItems: orderItems_1 });
                        _u.label = 7;
                    case 7:
                        // Musí být otestováno
                        this.setState({
                            showDeliveryAddressForm: (_f = (_e = (_d = this.props.location) === null || _d === void 0 ? void 0 : _d.state) === null || _e === void 0 ? void 0 : _e.showDeliveryAddressForm) !== null && _f !== void 0 ? _f : false,
                            selectedDeliveryType: (_j = (_h = (_g = this.props.location) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.deliveryTypePicked) !== null && _j !== void 0 ? _j : { id: 0, name: '', fee: 0 },
                            selectedPaymentType: (_m = (_l = (_k = this.props.location) === null || _k === void 0 ? void 0 : _k.state) === null || _l === void 0 ? void 0 : _l.paymentTypePicked) !== null && _m !== void 0 ? _m : { id: 0, name: '', fee: 0 },
                            filteredPaymentTypes: (_q = (_p = (_o = this.props.location) === null || _o === void 0 ? void 0 : _o.state) === null || _p === void 0 ? void 0 : _p.filteredPaymentTypes) !== null && _q !== void 0 ? _q : new Array(),
                            showSelectPaymentType: (_t = (_s = (_r = this.props.location) === null || _r === void 0 ? void 0 : _r.state) === null || _s === void 0 ? void 0 : _s.showSelectPaymentType) !== null && _t !== void 0 ? _t : false
                        });
                        return [2 /*return*/];
                }
            });
        });
    };
    Checkout.prototype.render = function () {
        var _this = this;
        var _a, _b;
        var _c = this.state, deliveryTypes = _c.deliveryTypes, errorMessage = _c.errorMessage, filteredPaymentTypes = _c.filteredPaymentTypes, isLoggedIn = _c.isLoggedIn, orderItems = _c.orderItems, selectedDeliveryAddress = _c.selectedDeliveryAddress, selectedDeliveryType = _c.selectedDeliveryType, selectedInvoicingAddress = _c.selectedInvoicingAddress, selectedPaymentType = _c.selectedPaymentType, showCreateAccountForm = _c.showCreateAccountForm, showDeliveryAddressForm = _c.showDeliveryAddressForm, userAddresses = _c.userAddresses, showSelectPaymentType = _c.showSelectPaymentType;
        var deliveryAddressValidationSchema = Yup.object().shape({
            deliveryAddress: Yup.object().shape({
                firstName: Yup.string().required("Jméno je vyžadováno!"),
                lastName: Yup.string().required("Příjmení je vyžadováno!"),
                phoneNumber: Yup.string().required("Telefonní číslo je vyžadováno!"),
                city: Yup.string().required("Město je vyžadováno!"),
                street: Yup.string().required("Ulice je vyžadována!"),
                zipCode: Yup.string().required("PSČ je vyžadováno!")
            })
        });
        var passwordValidationSchema = Yup.object().shape({
            password: Yup.object().shape({
                password: Yup.string()
                    .required("Heslo je vyžadováno!")
                    .min(8, "Heslo musí obsahovat nejméně 8 znaků!"),
                confirmPassword: Yup.string()
                    .required("Potvrzení hesla je vyžadováno!")
                    .min(8, "Heslo musí obsahovat nejméně 8 znaků!")
                    .oneOf([Yup.ref('password'), null], "Hesla se neshodují!")
            })
        });
        var validationSchema = Yup.object().shape({
            invoicingAddress: Yup.object().shape({
                firstName: Yup.string().required("Jméno je vyžadováno!"),
                lastName: Yup.string().required("Příjmení je vyžadováno!"),
                email: Yup.string().required("Email je vyžadován!").email("Nevalidní emailová adresa!"),
                phoneNumber: Yup.string().required("Telefonní číslo je vyžadováno!"),
                city: Yup.string().required("Město je vyžadováno!"),
                street: Yup.string().required("Ulice je vyžadována!"),
                zipCode: Yup.string().required("PSČ je vyžadováno!")
            }),
            deliveryTypePicked: Yup.string().required("Vyberte způsob dopravy!"),
            paymentTypePicked: Yup.string().required("Vyberte způsob platby!")
        });
        if (showCreateAccountForm) {
            validationSchema = validationSchema.concat(passwordValidationSchema);
        }
        if (showDeliveryAddressForm) {
            validationSchema = validationSchema.concat(deliveryAddressValidationSchema);
        }
        // Empty (init) objects
        var invoicingAddress = {
            id: undefined,
            firstName: '',
            lastName: '',
            email: '',
            phoneNumber: '',
            city: '',
            street: '',
            zipCode: ''
        };
        var deliveryAddress = {
            id: undefined,
            firstName: '',
            lastName: '',
            phoneNumber: '',
            city: '',
            street: '',
            zipCode: ''
        };
        var password = {
            password: '',
            confirmPassword: ''
        };
        // End of empty (init) objects
        return (React.createElement(React.Fragment, null,
            React.createElement("section", { className: "checkout" },
                React.createElement("div", { className: "container" },
                    React.createElement("h3", { className: "mb-4" }, "Vytvo\u0159en\u00ED objedn\u00E1vky"),
                    React.createElement("h4", null, "Mapa s oblast\u00ED doru\u010Den\u00ED"),
                    React.createElement("iframe", { src: "https://www.google.com/maps/d/embed?mid=1YBfeKo_95TG0zDl7VdZ_QFbvzP8VwtX6&ehbc=2E312F", width: "100%", height: "600" }),
                    React.createElement("div", { className: "checkout__form" }, orderItems.length
                        ? React.createElement(React.Fragment, null,
                            React.createElement(formik_1.Formik, { initialValues: {
                                    invoicingAddress: (selectedInvoicingAddress === "0") ? __assign({}, invoicingAddress) : (userAddresses.find(function (i) { return i.id.toString() === selectedInvoicingAddress; }) ||
                                        ((_a = this.props.history.location.state) === null || _a === void 0 ? void 0 : _a.invoicingAddress) || __assign({}, invoicingAddress)),
                                    deliveryAddress: selectedDeliveryAddress === "0" ? __assign({}, deliveryAddress) : undefined ||
                                        userAddresses.find(function (i) { return i.id.toString() === selectedDeliveryAddress; }) ||
                                        __assign({}, (_b = this.props.history.location.state) === null || _b === void 0 ? void 0 : _b.deliveryAddress) || __assign({}, deliveryAddress),
                                    password: __assign({}, password),
                                    deliveryTypePicked: selectedDeliveryType.id !== 0 ? selectedDeliveryType.id.toString() : '',
                                    paymentTypePicked: selectedPaymentType.id !== 0 ? selectedPaymentType.id.toString() : '2' // Init hodnota Bankovni prevod
                                }, enableReinitialize: true, validationSchema: validationSchema, onSubmit: function (formValues) { return _this.handleSubmit(formValues); } }, function (_a) {
                                var touched = _a.touched, errors = _a.errors, handleReset = _a.handleReset, handleSubmit = _a.handleSubmit, setFieldTouched = _a.setFieldTouched, handleChange = _a.handleChange, values = _a.values, setValues = _a.setValues, setFieldValue = _a.setFieldValue;
                                return (React.createElement(formik_1.Form, { onReset: handleReset, onSubmit: handleSubmit, noValidate: true },
                                    React.createElement(DeliveryAndPaymentTypeForm_1.default, { deliveryTypes: deliveryTypes, paymentTypes: filteredPaymentTypes, selectedDeliveryType: selectedDeliveryType, showSelectPaymentType: showSelectPaymentType, onDeliveryTypeChange: _this.handleDeliveryTypeChange, onPaymentTypeChange: _this.handlePaymentTypeChange, errors: errors, setFieldTouched: setFieldTouched, setFieldValue: setFieldValue, handleChange: handleChange, touched: touched }),
                                    React.createElement("h4", null, "Faktura\u010Dn\u00ED \u00FAdaje"),
                                    React.createElement("div", { className: "row" },
                                        React.createElement("div", { className: "col-lg-8 col-md-6" },
                                            isLoggedIn
                                                ? React.createElement(react_dropdown_1.default, { className: 'my-dropdown-root', controlClassName: 'checkout__dropdown__control', placeholderClassName: 'my-dropdown-placeholder', menuClassName: 'my-dropdown-menu', placeholder: 'Ulo\u017Een\u00E9 faktura\u010Dn\u00ED adresy', options: __spreadArray(__spreadArray([], userAddresses.filter(function (i) { return i.addressTypeID === ViewModels_1.AddressType.InvoicingAddress; }).map(function (address) {
                                                        return {
                                                            value: address.id.toString(),
                                                            label: "".concat(address.firstName, ", ").concat(address.lastName, ", ").concat(address.city, ", ").concat(address.street, " ...")
                                                        };
                                                    }), true), [{ value: '0', label: 'Nová fakturační adresa' }], false), onChange: _this.handleInvoicingAddressChange, value: selectedInvoicingAddress })
                                                : null,
                                            errorMessage
                                                ? React.createElement("div", { className: 'error-message' }, errorMessage)
                                                : null,
                                            React.createElement(InvoicingAddressForm_1.default, { errors: errors.invoicingAddress, handleChange: handleChange, setFieldTouched: setFieldTouched, touched: touched.invoicingAddress, values: values.invoicingAddress }),
                                            isLoggedIn
                                                ? null
                                                : React.createElement("div", { className: "checkout__input__checkbox" },
                                                    React.createElement("label", null,
                                                        "Vytvo\u0159it \u00FA\u010Det?",
                                                        React.createElement("input", { onChange: function () {
                                                                _this.handleShowCreateAccountFormChange();
                                                                setValues(__assign(__assign({}, values), { password: password }));
                                                            }, type: "checkbox", checked: showCreateAccountForm }),
                                                        React.createElement("span", { className: "checkmark" }))),
                                            showCreateAccountForm && !isLoggedIn
                                                ? React.createElement(CreateAccountForm_1.default, { errors: errors.password, handleChange: handleChange, setFieldTouched: setFieldTouched, touched: touched.password, values: values.password })
                                                : null,
                                            React.createElement("div", { className: "checkout__input__checkbox" },
                                                React.createElement("label", null,
                                                    "Doru\u010Dit na jinou adresu?",
                                                    React.createElement("input", { onChange: function () {
                                                            _this.handleShowDeliveryAddressFormChange();
                                                            setValues(__assign(__assign({}, values), { deliveryAddress: deliveryAddress }));
                                                        }, type: "checkbox", checked: showDeliveryAddressForm }),
                                                    React.createElement("span", { className: "checkmark" }))),
                                            showDeliveryAddressForm
                                                ? React.createElement(React.Fragment, null,
                                                    isLoggedIn
                                                        ? React.createElement(react_dropdown_1.default, { className: 'my-dropdown-root', controlClassName: 'checkout__dropdown__control', placeholderClassName: 'my-dropdown-placeholder', menuClassName: 'my-dropdown-menu', placeholder: 'Ulo\u017Een\u00E9 droru\u010Dovac\u00ED adresy', options: __spreadArray(__spreadArray([], userAddresses.filter(function (i) { return i.addressTypeID === ViewModels_1.AddressType.DeliveryAddress; }).map(function (address) {
                                                                return {
                                                                    value: address.id.toString(),
                                                                    label: "".concat(address.firstName, ", ").concat(address.lastName, ", ").concat(address.city, ", ").concat(address.street, " ...")
                                                                };
                                                            }), true), [{ value: '0', label: 'Nová doručovací adresa' }], false), onChange: _this.handleDeliveryAddressChange, value: selectedDeliveryAddress })
                                                        : null,
                                                    React.createElement(DeliveryAddressForm_1.default, { errors: errors.deliveryAddress, handleChange: handleChange, setFieldTouched: setFieldTouched, touched: touched.deliveryAddress, values: values.deliveryAddress }))
                                                : null),
                                        React.createElement("div", { className: "col-lg-4 col-md-6" },
                                            React.createElement("div", { className: "checkout__order" },
                                                React.createElement(OrderSummary_1.default, { orderItems: orderItems, deliveryType: selectedDeliveryType, paymentType: selectedPaymentType }),
                                                React.createElement("button", { type: "submit", className: "site-btn" }, "DOKON\u010CIT OBJEDN\u00C1VKU")))),
                                    React.createElement(react_router_dom_1.Link, { to: {
                                            pathname: "/cart",
                                            state: __assign(__assign({}, values), { showDeliveryAddressForm: showDeliveryAddressForm, showSelectPaymentType: showSelectPaymentType, filteredPaymentTypes: filteredPaymentTypes, deliveryTypePicked: selectedDeliveryType, paymentTypePicked: selectedPaymentType })
                                        }, className: "checkout__link" }, "Zp\u011Bt do ko\u0161\u00EDku")));
                            }))
                        : null)))));
    };
    return Checkout;
}(React.Component));
exports.default = Checkout;
//# sourceMappingURL=checkout.js.map