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 __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 __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 };
    }
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
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';
var PaymentEcComponent = /** @class */ (function (_super) {
    __extends(PaymentEcComponent, _super);
    function PaymentEcComponent(renderer, toastr, paymentService, checkoutService) {
        var _this = _super.call(this) || this;
        _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 = function () { return (__assign(__assign({}, _this.paymentService.getUserData().shippingAddress), _this.paymentService.getShipmentData())); };
        _this.setError = function (message) {
            _this.error = message;
        };
        _this.emitResult = function () { return __awaiter(_this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                this.paymentService.setStepReady(this.methodDataSubject.getValue(), null).then(function (res) {
                    _this.setLoading(false);
                });
                return [2 /*return*/];
            });
        }); };
        _this.setLoading = function (estado) {
            if (estado === void 0) { estado = true; }
            _this.loadingSubject.next(estado);
            return true;
        };
        _this.verifyValidate = function () {
            _this.setLoading();
            setTimeout(function (r) { return _this.emitResult(); }, 1000);
        };
        _this.setMethod = function (method) { return __awaiter(_this, void 0, void 0, function () {
            var result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.methodDataSubject.next(null);
                        return [4 /*yield*/, this.paymentService.putPayment(method.code)];
                    case 1:
                        result = _a.sent();
                        this.methodDataSubject.next(method);
                        return [2 /*return*/];
                }
            });
        }); };
        _this.submitForm = function (event) {
            try {
                //console.log("EVENT", event);
                event.preventDefault();
                return false;
            }
            catch (e) {
                //console.log('SE ROMOPIO EL PREVENT DEFAULT')
            }
        };
        _this.getPK = function (method) { return (method.config.public_key || method.public_key); };
        _this.isRedirectRedsys = function (code) { return code && code.toLocaleLowerCase().includes('redsys_redirect'); };
        _this.isRedirectCecaBank = function (code) { return code && code.toLocaleLowerCase().includes('ceca_bank_redirect'); };
        _this.isMP = function (code) { return code && code.toLocaleLowerCase() == ('mercado_pago'); };
        _this.isMPTarjetaDeCredito = function (code) { return code && code.toLocaleLowerCase().includes('credit'); };
        _this.isMethodOffline = function (code) { return code && code.toLocaleLowerCase().includes('offline'); };
        _this.isPeyPalExpress = function (code) { return code && code.toLocaleLowerCase().includes('paypal') && code.toLocaleLowerCase().includes('express'); };
        _this.isMobbex = function (code) { return code && code.toLocaleLowerCase().includes('mobbex'); };
        _this.isBancard = function (code) { return code && code.toLocaleLowerCase().includes('bancard'); };
        _this.isDecidir = function (code) { return code && code.toLocaleLowerCase().includes('decidir'); };
        _this.ecOnConstruct();
        return _this;
    }
    PaymentEcComponent.prototype.ngOnChanges = function () { };
    PaymentEcComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.paymentService.initialize(this.step_id);
        this.checkoutService.asociatedData$.subscribe(function (data) { return _this.total_amount = (data.find(function (item) { return item.type == 'total'; })).amount; });
        this.ecOnInit();
    };
    PaymentEcComponent.prototype.setActive = function (e) {
        var e_1, _a;
        var parent = e.target.parentElement.children;
        try {
            for (var parent_1 = __values(parent), parent_1_1 = parent_1.next(); !parent_1_1.done; parent_1_1 = parent_1.next()) {
                var button = parent_1_1.value;
                if (button.classList.contains('active')) {
                    button.classList.remove('active');
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (parent_1_1 && !parent_1_1.done && (_a = parent_1.return)) _a.call(parent_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        e.target.classList.add("active");
    };
    PaymentEcComponent.ctorParameters = function () { return [
        { 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);
    return PaymentEcComponent;
}(ComponentHelper));
export { PaymentEcComponent };
//# sourceMappingURL=data:application/json;base64, 