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 (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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 };
    }
};
import { Component, Input } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { OrdersService } from '../../../services/account/orders.service';
import { Constants } from '../../../core.consts';
import { ComponentHelper } from '../../../classes/component-helper';
var OrderEcComponent = /** @class */ (function (_super) {
    __extends(OrderEcComponent, _super);
    function OrderEcComponent(ordersService, activedRoute, router, consts) {
        var _this = _super.call(this) || this;
        _this.ordersService = ordersService;
        _this.activedRoute = activedRoute;
        _this.router = router;
        _this.consts = consts;
        _this.orderSubject = new BehaviorSubject({});
        _this.order$ = _this.orderSubject.asObservable();
        _this.order = null;
        _this.loading = true;
        _this.numberOrder = null;
        _this.toDate = function (date) { return moment(date).format('DD/MM/YYYY, h:mm:ss a'); };
        _this.callError = function () {
            _this.error = '?';
            _this.router.navigateByUrl('account/orders');
        };
        _this.volver = function () { return _this.router.navigateByUrl('account/orders'); };
        _this.ecOnConstruct();
        return _this;
    }
    OrderEcComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.loading = true;
        this.ordersService.selectedOrder$.subscribe(function (res) { return __awaiter(_this, void 0, void 0, function () {
            var order;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (this.numberOrder == null) {
                            this.numberOrder = this.activedRoute.snapshot.params.number;
                        }
                        if (!res) return [3 /*break*/, 1];
                        order = res;
                        return [3 /*break*/, 3];
                    case 1: return [4 /*yield*/, this.ordersService.findOrder(this.numberOrder)];
                    case 2:
                        order = _a.sent();
                        _a.label = 3;
                    case 3:
                        order && this.orderSubject.next(order);
                        !order && this.callError();
                        this.order = order;
                        this.loading = false;
                        return [2 /*return*/];
                }
            });
        }); }),
            function (err) {
                _this.ordersService.error$.toPromise().then(function (res) { return _this.error = res; });
                _this.loading = false;
                _this.callError();
            };
        this.ecOnInit();
    };
    OrderEcComponent.ctorParameters = function () { return [
        { type: OrdersService },
        { type: ActivatedRoute },
        { type: Router },
        { type: Constants }
    ]; };
    __decorate([
        Input()
    ], OrderEcComponent.prototype, "numberOrder", void 0);
    OrderEcComponent = __decorate([
        Component({
            selector: 'app-order-ec',
            template: "<main class=\"py-5\" id=\"orderEcComponent\">\n    <div class=\"container\">\n        <div class=\"wrap\" *ngIf=\"!loading; else loadingView\">\n            <div *ngIf=\"order; else noOrder\">\n                \n                <div class=\"row justify-content-between\">\n                    <div class=\"col-sm col-12 font-brandon\">\n                        <h4 class=\"tit1 \">{{ ('order' | translate) + ': ' + order.number }}</h4>\n                    </div>\n                    <a (click)=\"volver()\" class=\"col-auto text-end\">\n                        <button class=\"btn btvolver bg-gray text-white\">{{ 'back-to-orders' | translate }}</button>\n                    </a>\n                </div>\n                \n                <section id=\"orders\">\n                    <div>\n                        <div class=\"row\">\n                            <div class=\"col-md-12 col-12 font-brandon\">\n                                <div class=\"row item\">\n                                    <div class=\"col-md-12 col-12 font-brandon\">\n                                        <div class=\"row\">\n                                            <div class=\"col-md-2 col-12\">\n                                                <span class=\"st\">{{ 'payment-state' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ order.payments[0].state | translate }}\n                                                </p>\n                                            </div>\n                                            <div class=\"col-md-2 col-12 font-brandon\">\n                                                <span class=\"st\">{{ 'shipment-state' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ order.shipments[0].state | translate }}\n                                                </p>\n                                            </div>\n                                            <div class=\"col-md-2 col-12 font-brandon\">\n                                                <span class=\"st\">{{ 'payment-method' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ order.payments[0]?.method?.name | translate }}\n                                                </p>\n                                            </div>\n                                            <div class=\"col-md-2 col-12 font-brandon\">\n                                                <span class=\"st\">{{ 'shipment-method' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ order.shipments[0].method.name }}\n                                                </p>\n                                            </div>\n                                            <div class=\"col-md-1 col-12 font-brandon\">\n                                                <span class=\"st\">{{ 'date' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ toDate(order.checkoutCompletedAt) | translate }}\n                                                </p>\n                                            </div>\n                                            <div class=\"col-md-1 col-12 font-brandon\">\n                                                <span class=\"st\">{{ 'total' | translate }}:</span>\n                                                <p class=\"\">\n                                                    {{ (order.totals.total) | ecCurrencySymbol}}\n                \n                                                </p>\n                                            </div>\n                                            <ng-container *ngIf=\"order?.invoice\">\n                                                <div class=\"col-md-2 col-12 font-brandon\">\n                                                    <span class=\"st\">{{ 'invoices' | translate | titlecase }}:</span>\n                                                    <p class=\"\">\n                                                        <a target=\"_blank\" [href]=\"consts.getUrlBase().slice(0, -1) + order.invoice\"\n                                                            class=\"btn btn-link btn-invoice\">\n                                                            <i class=\"fas fa-file-download\"></i>\n                                                            {{ 'download' | translate }}\n                                                        </a>\n                                                    </p>\n                                                </div>\n                                            </ng-container>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                        </div>\n                    </div>\n                </section>\n                \n                <div class=\"container py-md-5 py-3\">\n                    <div *ngIf=\"order.items.length; else noProducts\" class=\"row\">\n                        <div class=\"col-2 text-center font-sm font-brandon d-none d-md-block\">\n                            {{ 'product' | translate | uppercase }}\n                        </div>\n                        <div class=\"col-4 text-center font-sm font-brandon d-none d-md-block\">\n                            {{ 'description' | translate | uppercase }}\n                        </div>\n                        <div class=\"col-2 text-center font-sm font-brandon d-none d-md-block\">\n                            {{ 'unit-price' | translate | uppercase }}\n                        </div>\n                        <div class=\"col-2 text-center font-sm font-brandon d-none d-md-block\">\n                            {{ 'quantity' | translate | uppercase }}\n                        </div>\n                        <div class=\"col-2 text-center font-sm font-brandon d-none d-md-block\">\n                            {{ 'total' | translate | uppercase }}\n                        </div>\n                        <div class=\"col-12 border-bottom-solid d-none d-md-block\"></div>\n                    </div>\n                    <ng-container *ngFor=\"let item of order.items\">\n                        <div class=\"row cart-items\">\n                            <div class=\"col-5 col-md-1 p-2\">\n                                <ng-container *ngIf=\"order.items[0].product.variants[0]?.images?.length ; else defaultpicture\">\n                                    <img class=\"smc maxwidth img-fluid rounded-custom \" [src]=\"consts.mediaUrl() +   order.items[0].product.variants[0].images[0]\" alt=\"\">\n                                </ng-container>\n                                <ng-template #defaultpicture>\n                                    <img *ngIf=\"order.items[0].product.picturesdefault\" class=\"smc maxwidth img-fluid rounded-custom\"\n                                        [src]=\"consts.mediaUrl() + order.items[0].product.picturesdefault[0]\" alt=\"\">\n                                </ng-template>\n                            </div>\n                            <div\n                                class=\"col-md-4 col-7 px-md-5 text-left flex-column flex-md-row justify-content-start d-flex align-items-center\">\n                                <p class=\"font-brandon d-flex w-100\">\n                                    {{ item.product.name }} (Cod:{{ item.product.variants[0].code }})\n                                </p>\n                                <div class=\"container d-md-none\">\n                                    <div class=\"row\">\n                                        <div class=\"col-4\">\n                                            <p class=\"text-center w-100 m-0\"> {{ item.quantity }}</p>\n                                        </div>\n                                        <div class=\"col-4 font-xl\">\n                                            <p class=\"text-center w-100 m-0\"> {{ (item.product.variants[0].saleprice ? item.product.variants[0].saleprice : item.product.variants[0].price) | ecCurrencySymbol}}</p>\n                                        </div>\n                                        <div class=\"col-4 font-xl\">\n                                            <p class=\"text-center w-100 m-0\"> {{ ((item.product.variants[0].saleprice ? item.product.variants[0].saleprice : item.product.variants[0].price) * item.quantity) | ecCurrencySymbol}}</p>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"col-3 d-none d-md-flex text-center px-5 align-items-center\">\n                                <p class=\"text-center w-100 m-0\">\n                                    {{ (item.product.variants[0].saleprice ? item.product.variants[0].saleprice  : item.product.variants[0].price) | ecCurrencySymbol}}\n                                </p>\n                            </div>\n                            <div class=\"col-2 d-none d-md-flex align-items-center\">\n                                <p class=\"text-center w-100 m-0\"> {{ item.quantity }}</p>\n                            </div>\n                            <div class=\"col-2 d-none d-md-flex text-center align-items-center\">\n                                <p class=\"text-center w-100 m-0\">\n                                    {{ ((item.product.variants[0].saleprice ? item.product.variants[0].saleprice  : item.product.variants[0].price) * item.quantity) | ecCurrencySymbol}}</p>\n                            </div>\n                        </div>\n                    </ng-container>\n                </div>\n                \n                <div class=\"container\">\n                    <div class=\"row border-top-solid\">\n                        <div class=\"col-12 col-md-6\"></div>\n                        <div class=\"col-12 col-md-6\">\n                            <div class=\"row py-4\">\n                                <div class=\"col-6 font-brandon font-md text-gray border-bottom \">{{ 'total-products' | translate }}</div>\n                                <div class=\"col-6 font-brandon font-md text-gray border-bottom  text-right\">\n                                    {{ (order.totals.items) | ecCurrencySymbol }}\n                                </div>\n                                \n                                <div class=\"col-6 font-brandon font-md text-gray border-bottom \">{{ 'shipment' | translate }}</div>\n                                <div class=\"col-6 font-brandon font-md text-gray border-bottom  text-right\">\n                                    {{ (order.totals.shipping || '0') | ecCurrencySymbol }}\n                                </div>\n                                \n                                <div *ngIf=\"order.totals.promotion && order.totals.promotion != 0\"\n                                    class=\"col-6 font-brandon font-md text-gray border-bottom \">{{ 'discount' | translate }}</div>\n                                <div *ngIf=\"order.totals.promotion && order.totals.promotion != 0\"\n                                    class=\"col-6 font-brandon font-md text-gray border-bottom  text-right text-right\">\n                                    {{ (order.totals.promotion) | ecCurrencySymbol }}</div>\n                                \n                                <div *ngIf=\"order.totals.taxes && order.totals.taxes != 0 \" class=\"col-6 font-brandon font-md text-gray border-bottom \">\n                                    {{ 'taxes' | translate }}</div>\n                                <div *ngIf=\"order.totals.taxes && order.totals.taxes != 0\" class=\"col-6 font-brandon font-md text-gray border-bottom  text-right\">\n                                    {{ (order.totals.taxes) | ecCurrencySymbol }}</div>\n                                \n                                <div class=\"col-6 font-brandon font-md\">{{ 'total' | translate | uppercase }}</div>\n                                <div class=\"col-6 font-brandon font-md text-right\">\n                                    {{ (order.totals.total) | ecCurrencySymbol }}\n                                </div>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </div>\n\n</main>\n\n<ng-template #noOrder>\n    <div class=\"w-100 h-50\">\n        <div class=\"d-flex flex-row justify-content-center align-items-center text-center\">\n            <h5>{{ 'no-orders' | translate }}</h5>\n        </div>\n    </div>\n</ng-template>\n\n<ng-template #loadingView>\n    <div class=\"w-100 h-50\">\n        <div class=\"d-flex flex-row justify-content-center align-items-center text-center\">\n            <app-loading-full-ec></app-loading-full-ec>\n        </div>\n    </div>\n</ng-template>",
            styles: [""]
        })
    ], OrderEcComponent);
    return OrderEcComponent;
}(ComponentHelper));
export { OrderEcComponent };
//# sourceMappingURL=data:application/json;base64, 