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());
    });
};
import { Component, Renderer2, ElementRef, ViewChild, Input, OnChanges, OnInit, Output, EventEmitter } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ComponentHelper } from '../../../classes/component-helper';
import { CheckoutService } from '../../../services/checkout/checkout.service';
import { PaymentService } from '../../../services/checkout/payment.service';
import { ToastService } from '../../../utils/toast.service';
let PaymentEcComponent = class PaymentEcComponent extends ComponentHelper {
    constructor(renderer, toastr, paymentService, checkoutService) {
        super();
        this.renderer = renderer;
        this.toastr = toastr;
        this.paymentService = paymentService;
        this.checkoutService = checkoutService;
        this.methodDataSubject = new BehaviorSubject(null);
        this.loadingSubject = new BehaviorSubject(false);
        this.loading_internal = false;
        this.loading = true;
        this.loading_internal_mp = false;
        this.method_data$ = this.methodDataSubject.asObservable();
        this.loading$ = this.loadingSubject.asObservable();
        this.allData = () => (Object.assign(Object.assign({}, this.paymentService.getUserData().shippingAddress), this.paymentService.getShipmentData()));
        this.setError = (message) => {
            this.error = message;
        };
        this.emitResult = () => __awaiter(this, void 0, void 0, function* () {
            this.paymentService.setStepReady(this.methodDataSubject.getValue(), null).then(res => {
                this.setLoading(false);
            });
        });
        this.setLoading = (estado = true) => {
            this.loadingSubject.next(estado);
            return true;
        };
        this.verifyValidate = () => {
            this.setLoading();
            setTimeout(r => this.emitResult(), 1000);
        };
        this.setMethod = (method) => __awaiter(this, void 0, void 0, function* () {
            this.methodDataSubject.next(null);
            let result = yield this.paymentService.putPayment(method.code);
            this.methodDataSubject.next(method);
            // this.isMP(method.code) && this.getPreference();
        });
        this.submitForm = (event) => {
            try {
                //console.log("EVENT", event);
                event.preventDefault();
                return false;
            }
            catch (e) {
                //console.log('SE ROMOPIO EL PREVENT DEFAULT')
            }
        };
        this.getPK = (method) => (method.config.public_key || method.public_key);
        this.isRedirectRedsys = (code) => code && code.toLocaleLowerCase().includes('redsys_redirect');
        this.isRedirectCecaBank = (code) => code && code.toLocaleLowerCase().includes('ceca_bank_redirect');
        this.isMP = (code) => code && code.toLocaleLowerCase() == ('mercado_pago');
        this.isMPTarjetaDeCredito = (code) => code && code.toLocaleLowerCase().includes('credit');
        this.isMethodOffline = (code) => code && code.toLocaleLowerCase().includes('offline');
        this.isPeyPalExpress = (code) => code && code.toLocaleLowerCase().includes('paypal') && code.toLocaleLowerCase().includes('express');
        this.isMobbex = (code) => code && code.toLocaleLowerCase().includes('mobbex');
        this.isBancard = (code) => code && code.toLocaleLowerCase().includes('bancard');
        this.isDecidir = (code) => code && code.toLocaleLowerCase().includes('decidir');
        this.ecOnConstruct();
    }
    ngOnChanges() { }
    ngOnInit() {
        this.paymentService.initialize(this.step_id);
        this.checkoutService.asociatedData$.subscribe((data) => this.total_amount = (data.find(item => item.type == 'total')).amount);
        this.ecOnInit();
    }
    setActive(e) {
        const parent = e.target.parentElement.children;
        for (const button of parent) {
            if (button.classList.contains('active')) {
                button.classList.remove('active');
            }
        }
        e.target.classList.add("active");
    }
};
PaymentEcComponent.ctorParameters = () => [
    { type: Renderer2 },
    { type: ToastService },
    { type: PaymentService },
    { type: CheckoutService }
];
__decorate([
    Input()
], PaymentEcComponent.prototype, "step_id", void 0);
__decorate([
    ViewChild('formContainer')
], PaymentEcComponent.prototype, "mercadopago_button", void 0);
PaymentEcComponent = __decorate([
    Component({
        selector: 'app-payment-ec',
        template: "<div class=\"container-fluid\" *ngIf=\"(paymentService.methods$ | async) as methods\">\n\n    <div class=\"row\">\n        <div class=\"col-12\">\n            <div class=\"card \">\n                <div class=\"card-header text-dark text-center\">\n                    <h4>{{ 'select-method' | translate }}</h4>\n                    <div class=\"btn-toolbar justify-content-center\" role=\"toolbar\" aria-label=\"Envios toolbar\">\n                        <div class=\"btn-group group-shipping\" role=\"group\" aria-label=\"Grupo botones envio\">\n                            <div class=\"d-flex align-content-start flex-wrap btn-group\">\n                                <button type=\"button\" class=\"btn btn-outline-secondary\"\n                                    *ngFor=\"let method of methods; let x = index\"\n                                    (click)=\"setMethod(method) ; setActive($event)\">\n                                    {{ method.name | translate }}\n                                </button>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n                <div class=\"card-body text-center\">\n                    <div class=\"row justify-content-center\" *ngIf=\"(method_data$ | async) as method\">\n                        <ng-container *ngIf=\"!loading_internal ; else loading\">\n                            <div class=\"method-container text-dark\" *ngIf=\"isMP(method.code)\">\n                                <p id=\"faqs\" class=\"qt px-5 \">{{ method.description }}</p>\n                                <p class=\"px-5\">{{ method.instructions }}</p>\n                                <app-mp-redirect-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [paymentServiceInst]=\"paymentService\" [allData]=\"allData()\"></app-mp-redirect-ec>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isMPTarjetaDeCredito(method.code)\">\n                                <div class=\"row\">\n                                    <div class=\"col-12\">\n                                        <p id=\"faqs\" class=\"qt px-5 \">{{ method.description }}</p>\n                                        <p class=\"px-5\">{{ method.instructions }}</p>\n                                        <div app-mp-credit-ec (ready)=\"verifyValidate()\" [public_key]=\"getPK(method)\"\n                                            [user_data]=\"allData()\" [total_amount]=\"total_amount\">\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\"\n                                *ngIf=\"isRedirectRedsys(method.code)\">\n                                <div class=\"row\">\n                                    <div class=\"col-12\">\n                                        <ng-container *ngIf=\"!method.code.includes('bizum') && !method.code.includes('_out_')\">\n                                            <app-redsys-redirect-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\">\n                                            </app-redsys-redirect-ec>\n                                        </ng-container>\n                                        <ng-container *ngIf=\"method.code.includes('bizum') || method.code.includes('_out_')\">\n                                            <app-redsys-redirect-out-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\">\n                                            </app-redsys-redirect-out-ec>\n                                        </ng-container>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isRedirectCecaBank(method.code)\">\n                                <div class=\"row\">\n                                    <div class=\"col-12\">\n                                        <app-ceca-redirect-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\">\n                                        </app-ceca-redirect-ec>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isPeyPalExpress(method.code)\">\n                                <div class=\"container\">\n                                    <div class=\"row justify-content-center\">\n                                        <div class=\"col-12\">\n                                            <app-paypal-express-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\"\n                                                [total_amount]=\"total_amount\">\n                                            </app-paypal-express-ec>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isMobbex(method.code)\">\n                                <div class=\"container\">\n                                    <div class=\"row justify-content-center\">\n                                        <div class=\"col-12\">\n                                            <app-mobbex-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\" [paymentServiceInst]=\"paymentService\"\n                                                [total_amount]=\"total_amount\">\n                                            </app-mobbex-ec>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isBancard(method.code)\">\n                                <div class=\"container\">\n                                    <div class=\"row justify-content-center\">\n                                        <div class=\"col-12\">\n                                            <app-bancard-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\"\n                                                [paymentServiceInst]=\"paymentService\" [total_amount]=\"total_amount\">\n                                            </app-bancard-ec>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark text-left\" *ngIf=\"isDecidir(method.code)\">\n                                <div class=\"container\">\n                                    <div class=\"row justify-content-center\">\n                                        <div class=\"col-12\">\n                                            <app-decidir-ec (ready)=\"verifyValidate($event)\" [method]=\"method\" [user_data]=\"allData()\" [paymentServiceInst]=\"paymentService\"\n                                                [total_amount]=\"total_amount\">\n                                            </app-decidir-ec>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                            <div class=\"method-container text-dark\" *ngIf=\"isMethodOffline(method.code)\">\n                                <p id=\"faqs\" class=\"qt px-5\">{{ method.description }}</p>\n                                <p class=\"px-5\">{{ method.instructions }}</p>\n                                <div class=\"end-button\">\n                                    <button class=\"btn comprar\" (click)=\"setLoading() && verifyValidate()\">{{  ('pay-with-offline'| translate) }}</button>\n                                </div>\n                                <ng-container *ngIf=\"(loading$ | async) as load\">\n                                    <div class=\"mt-2\" *ngIf=\"load\">\n                                        <app-loading-inline-ec></app-loading-inline-ec>\n                                    </div>\n                                </ng-container>\n                            </div>\n                            <div class=\"method-container text-dark\" *ngIf=\"method.code == 'bank_transfer'\">\n                                <p id=\"faqs\" class=\"qt px-5\">{{ method.description }}</p>\n                                <p class=\"px-5\">{{ method.instructions }}</p>\n                                <div class=\"end-button\">\n                                    <button class=\"btn comprar\" (click)=\"setLoading() && verifyValidate()\">{{\n                                        ('pay-with-transfer'\n                                        | translate) }}</button>\n                                </div>\n                                <ng-container *ngIf=\"(loading$ | async) as load\">\n                                    <div class=\"mt-2\" *ngIf=\"load\">\n                                        <app-loading-inline-ec></app-loading-inline-ec>\n                                    </div>\n                                </ng-container>\n                            </div>\n                        </ng-container>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </div>\n</div>\n\n<ng-template #mercadoPago>\n    <div class=\"row \">\n        <div class=\"col-12 text-center\">\n            <app-loading-inline-ec *ngIf=\"loading_internal_mp\"></app-loading-inline-ec>\n            <form action=\"javascript:void(0)\" #formContainer></form>\n        </div>\n    </div>\n</ng-template>\n\n<ng-template #loading>\n    <app-loading-inline-ec></app-loading-inline-ec>\n</ng-template>",
        providers: [PaymentService],
        styles: ["div.col-12 form{text-align:center}.option-container>div{margin-bottom:15px}@media only screen and (min-width:600px){.option-container{display:flex;justify-content:space-between;margin-top:20px}}.method-container{width:100%}.active{background-color:#000!important;color:#fff!important}.comprar{background:#000;color:#fff;display:inline-block;font-size:18px;font-weight:600;padding:10px 25px;text-decoration:none;text-transform:uppercase}"]
    })
], PaymentEcComponent);
export { PaymentEcComponent };
//# sourceMappingURL=data:application/json;base64, 