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;
};
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import * as moment from 'moment';
import { filter } from 'rxjs/operators';
import { ComponentHelper } from '../../../classes/component-helper';
import { Constants } from '../../../core.consts';
import { OrdersService } from '../../../services/account/orders.service';
// import { OwlOptions } from 'projects/ng-easycommerce/src/lib/ec-component/product-detail-ec/node_modules/projects/ng-easycommerce/src/lib/ec-component/home-ec/node_modules/ngx-owl-carousel-o';
let OrdersEcComponent = class OrdersEcComponent extends ComponentHelper {
    constructor(ordersService, router, consts) {
        super();
        this.ordersService = ordersService;
        this.router = router;
        this.consts = consts;
        this.loading = true;
        this.sortedByNewest = orders => orders && orders.length && orders.sort((anOrder, otherOrder) => anOrder.number > otherOrder.number ? -1 : 1);
        this.goToOrder = (order) => {
            this.ordersService.setSelectedOrder(order);
            this.router.navigateByUrl((`account/orders/${order.number}`));
        };
        this.toDate = (date) => moment(date).format('DD/MM/YYYY, h:mm:ss a');
        this.optionsBox = {
            loop: true,
            autoplay: true,
            smartSpeed: 950,
            margin: 10,
            dots: false,
            dotsData: false,
            navText: ["", ""],
            responsive: {
                0: {
                    items: 1,
                },
                600: {
                    items: 1,
                },
                1000: {
                    items: 1,
                }
            }
        };
        this.mediaUrl = this.consts.mediaUrl();
        this.ecOnConstruct();
    }
    ngOnInit() {
        this.loading = true;
        this.ordersService.updateOrders();
        this.ordersService.orders$.pipe(filter(or => or)).subscribe(orders => {
            this.orders = this.sortedByNewest(orders);
            this.loading = false;
        }, err => {
            this.loading = false;
            this.error = 'orders-error';
        });
        this.ecOnInit();
    }
};
OrdersEcComponent.ctorParameters = () => [
    { type: OrdersService },
    { type: Router },
    { type: Constants }
];
OrdersEcComponent = __decorate([
    Component({
        selector: 'app-orders-ec',
        template: "<div class=\"container\" id=\"ordersEcComponent\">\n\n    <div class=\"row w-100 mx-auto py-4\">\n        <section id=\"orders\" class=\"w-100\" *ngIf=\"!loading; else loadingView\">\n            <div *ngIf=\"orders && orders.length; else noOrders\">\n                <div class=\"row\">\n                    <div class=\"col-md-12 col-12\">\n                        <div class=\"row item\" *ngFor=\"let order of orders\">\n                            <div class=\"col-md-1 col-4\">\n                                <ng-container *ngIf=\"order.items[0].product.variants[0]?.images?.length ; else defaultpicture\">\n                                    <img class=\"smc maxwidth\" [src]=\"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\"\n                                        [src]=\"mediaUrl + order.items[0].product.picturesdefault[0]\" alt=\"\">\n                                </ng-template>\n                            </div>\n                            <div class=\"col-md-11 col-8\">\n                                <div class=\"row\">\n                                    <div class=\"col-md-1 col-12\">\n                                        <span class=\"st\">{{ 'order' | translate }}:</span>\n                                        <p class=\"price\">\n                                            {{ order.number }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-2 col-12\">\n                                        <span class=\"st\">{{ 'payment-state' | translate }}:</span>\n                                        <p class=\"price\">\n                                            {{ order.payments[0].state | translate | titlecase }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-2 col-12\">\n                                        <span class=\"st\">{{ 'shipment-method' | translate }}:</span>\n                                        <p class=\"price\">\n                                            {{ order.shipments[0].method.name }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-2 col-12\">\n                                        <span class=\"st\">{{ 'shipment-state' | translate }}:</span>\n                                        <p class=\"price\">\n                                            {{ order.shipments[0].state | translate | titlecase }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-2 col-12\">\n                                        <span class=\"st\">{{ 'date' | translate }}:</span>\n                                        <p class=\"price\">\n                                            {{ toDate(order.checkoutCompletedAt) | translate }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-1 col-12\">\n                                        <span class=\"st\">{{ 'total' | translate }}:</span>\n                                        <p class=\"\">\n                                            {{ (order.totals.total) | ecCurrencySymbol }}\n                                        </p>\n                                    </div>\n                                    <div class=\"col-md-2 col-12 text-md-right\">\n                                        <button class=\"btn btdetalle\" (click)=\"goToOrder(order)\">{{\n                                            'see-order' | translate }}</button>\n                                    </div>\n                                </div>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </section>\n    </div>\n</div>\n\n<ng-template #noOrders>\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 #errorView>\n    <div class=\"w-100 h-50\">\n        <div class=\"d-flex flex-row justify-content-center align-items-center text-center\">\n            <h4>{{ 'orders-error' | translate }}</h4>\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: [""]
    })
], OrdersEcComponent);
export { OrdersEcComponent };
//# sourceMappingURL=data:application/json;base64, 