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 __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
import { Component, ElementRef, OnInit, Renderer2, ViewChild } from '@angular/core';
import { Router, Event, NavigationStart } from '@angular/router';
import { filter } from 'rxjs/operators';
import { Constants } from '../../core.consts';
import { CartService } from '../../services/cart.service';
import { OptionsService } from '../../services/options.service';
import { ParametersService } from '../../services/parameters.service';
import { ProductsService } from '../../services/products/products.service';
import { AuthService } from '../../services/auth.service';
import { ComponentHelper } from '../../classes/component-helper';
import { TranslateService } from '@ngx-translate/core';
var HeaderEcComponent = /** @class */ (function (_super) {
    __extends(HeaderEcComponent, _super);
    function HeaderEcComponent(router, consts, cartService, optionsService, paramsService, productsService, authService, translate, renderer) {
        var _this = _super.call(this) || this;
        _this.router = router;
        _this.consts = consts;
        _this.cartService = cartService;
        _this.optionsService = optionsService;
        _this.paramsService = paramsService;
        _this.productsService = productsService;
        _this.authService = authService;
        _this.translate = translate;
        _this.renderer = renderer;
        //og elden
        _this.menuItems = [];
        _this.menuSections = [];
        _this.attributes = [];
        _this.categories = [];
        _this.envetUrlTransparent = ["/home", "/"];
        _this.params = {};
        _this.toggled = false;
        _this.updateMenuItem = function (title, elements) {
            var _a, _b;
            var index = _this.menuItems.findIndex(function (element) { return element.title == title; });
            if (index != null && index >= 0) {
                _this.menuItems[index].children = _this.optionsService.generateMenu(elements);
            }
            else {
                if (title == 'attributes') {
                    (_a = _this.attributes).push.apply(_a, __spread(_this.optionsService.generateMenu(elements)));
                    _this.attributes = _this.updateMenuItemLastCreated(_this.attributes);
                }
                if (title == 'categories') {
                    (_b = _this.categories).push.apply(_b, __spread(_this.optionsService.generateMenu(elements)));
                    _this.categories = _this.updateMenuItemLastCreated(_this.categories);
                }
            }
        };
        _this.nagivate = function (url) { return _this.router.navigateByUrl("/" + url); };
        _this.logout = function () {
            _this.authService.logout();
            _this.router.navigateByUrl('home');
        };
        _this.setSearchValue = function (event) {
            event.key == 'Enter' && _this.getCollectionSearch();
            _this.searchValue = event.target.value;
        };
        _this.getCollectionSearch = function () { return _this.router.navigateByUrl('/collection?search=' + _this.searchValue); };
        _this.toogleToolbar = function () {
            console.log('LLAMA AL TOOGLE');
            if (_this.menu_button.nativeElement.classList.contains('d-none')) {
                _this.renderer.removeClass(_this.menu_button, 'd-none');
                _this.renderer.addClass(_this.menu_button, 'active-mobile');
            }
            else {
                _this.renderer.addClass(_this.menu_button, 'd-none');
                _this.renderer.removeClass(_this.menu_button, 'active-mobile');
            }
        };
        _this.changeLanguage = function (lang) {
            _this.consts.setLocale(lang);
            window.location.reload();
        };
        _this.changeUrlTransparent = function (urlTransparent) {
            if (urlTransparent === void 0) { urlTransparent = []; }
            return urlTransparent;
        };
        _this.subscribeAttributes = function (arrayAttributes) {
        };
        _this.subscribeCategories = function (arrayCategories) {
        };
        _this.updateMenuItemLastCreated = function (arrayMenu) { return arrayMenu; };
        _this.changeUrlNavigation = function (url) { };
        _this.envetUrlTransparent = _this.changeUrlTransparent(_this.envetUrlTransparent);
        _this.router.events.subscribe(function (event) {
            if (event instanceof NavigationStart) {
                var url_1 = event.url;
                _this.changeUrlNavigation(url_1);
                _this.envetUrlTransparent.find(function (evUrl) { return evUrl === url_1; }) != undefined
                    ? _this.transparent = true
                    : _this.transparent = false;
            }
        });
        // menu
        _this.optionsService.categories.pipe(filter(function (cat) { return cat.length > 0; })).subscribe(function (res) {
            _this.updateMenuItem('categories', res);
            _this.subscribeCategories(res);
        });
        _this.optionsService.attributes.pipe(filter(function (atr) { return atr.length > 0; })).subscribe(function (res) {
            _this.updateMenuItem('attributes', res);
            _this.subscribeAttributes(res);
        });
        _this.ecOnConstruct();
        return _this;
    }
    HeaderEcComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.paramsService.parameters.subscribe(function (res) { return _this.params = res; });
        var mediaQuery = window.matchMedia('(max-width: 992px)');
        this.mediaMenu = mediaQuery.matches;
        this.ecOnInit();
    };
    HeaderEcComponent.ctorParameters = function () { return [
        { type: Router },
        { type: Constants },
        { type: CartService },
        { type: OptionsService },
        { type: ParametersService },
        { type: ProductsService },
        { type: AuthService },
        { type: TranslateService },
        { type: Renderer2 }
    ]; };
    __decorate([
        ViewChild("menu")
    ], HeaderEcComponent.prototype, "menu_button", void 0);
    HeaderEcComponent = __decorate([
        Component({
            selector: 'app-header-ec',
            template: "<!-- <header [class]=\"(!transparent ? 'no-banner' : '')\" id=\"header-principal\">\n     <div class=\"row border-color-buttom-gray m-0 d-none d-md-block\" id=\"novedades\">\n          <div class=\"col-12 py-2\">\n               {{ (params && params.header) || 'Sin informaci\u00F3n de cabecera' }}\n          </div>\n     </div>\n     <div class=\"row encabezado-superior m-0 d-flex justify-content-center\" id=\"top-menu-principal\">\n          <div class=\"col-md-6 col-3 p-md-3 p-2\">\n               <a routerLink=\"/home\">\n                    <img src=\"assets/image/logo.png\" id=\"logo-superior\" class=\"ml-md-4 ml-1\">\n               </a>\n          </div>\n          <div class=\"col-md-6 col-9 px-md-5 px-2 d-flex align-items-center justify-content-end\">\n               <ul class=\"nav d-flex align-items-center justify-content-end\">\n                    <li class=\"px-2 outside-menu\">\n                         <div class=\"order-3 order-lg-1 input-search pt-3\">\n                              <form (submit)=\"$event.preventDefault()\" class=\"navbar-form navbar-left m-1\">\n                                   <div class=\"input-group input-group-sm mb-3\" >\n                                        <input type=\"text\" class=\"form-control input-rounded bg-transparent border-left-none\" placeholder=\"Buscar producto\"\n                                             aria-label=\"Username\" aria-describedby=\"basic-addon1\"  (keyup)=\"setSearchValue($event)\">\n                                        <div class=\"input-group-prepend\" (click)=\"getCollectionSearch()\" role=\"button\">\n                                             <span class=\"input-group-text icon-rounded bg-transparent border-right-none\" id=\"basic-addon1\">\n                                                  <a class=\"color-white\"><img src=\"assets/svg/search.svg\"></a>\n                                             </span>\n                                        </div>\n                                   </div>\n                              </form>\n                         </div>\n                    </li>\n                    <li class=\"px-2 outside-menu\">\n                         <a routerLink=\"cart\" class=\"color-white\"><img src=\"assets/svg/cart.svg\"></a>\n                    </li>\n                    <li class=\"px-2 outside-menu\">\n                         <a [routerLink]=\"'/account'\" *ngIf=\"(authService.loggedIn | async); else sessionOptionsViewMobile\" class=\"color-white\"><img src=\"assets/svg/user.svg\"></a>\n                         <ng-template #sessionOptionsViewMobile>\n                              <a [routerLink]=\"'/auth/login'\" class=\"color-white\"><img src=\"assets/svg/user.svg\"></a>\n                         </ng-template>\n                    </li>\n                    <li class=\"px-2 outside-menu\">\n                         <a disabled style=\"vertical-align: -webkit-ecline-middle;\"\n                              class=\"color-white ff-ubuntu-light font-sm\">ES</a>\n                    </li>\n                    <li class=\"px-2 d-inline-block d-md-none\">\n                         <a id=\"openMenu\" class=\"color-white\" (click)=\"toogleToolbar()\">\n                              <img src=\"assets/svg/menu.svg\" class=\"open-m\" >\n                              <img src=\"assets/svg/close.svg\" class=\"close-m\">\n                         </a>\n                    </li>\n               </ul>\n          </div>\n          <div class=\"col-11 border-color-buttom-gray d-none d-md-block\"></div>\n     </div>\n     <nav class=\"py-md-3 py-0 w-100 d-none d-md-block\" id=\"menu-principal\" #menu>\n          <ul class=\"nav d-flex flex-md-row flex-column justify-content-center\">\n               <li class=\"dropdown separador-left\">\n                    <a class=\"dropdown-toggle color-white color-hover-golden ff-ubuntu-light py-md-2 py-3 px-4 font-sm\"\n                         data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\" data-target=\"#buscador\"\n                         role=\"button\">\n                         CAT\u00C1LOGO\n                    </a>\n                    <ul class=\"dropdown-menu mega-menu dropdown-menu-right mt-md-2 mt-0\" role=\"menu\">\n                         <div class=\"flex-md-row flex-column py-0 d-flex align-items-start justify-content-center\">\n                              <div class=\"row mega-menu-center px-md-3 px-0\">\n                                   <div class=\"col-sm py-3 box-submenu\"\n                                        *ngFor=\"let category of categories; let i = index\">\n                                        <div class=\"row\">\n                                             <div class=\"col-3 col-md-4 p-0\">\n                                                  <img [src]=\"consts.mediaUrl() + category.images[0].path\"\n                                                       class=\"w-100\">\n                                             </div>\n                                             <div class=\"col-9 col-md-8 py-2 pr-0\">\n                                                  <a [routerLink]=\"category.path\">\n                                                       <h5 class=\"ff-ubuntu-semi-bold font-xl\">{{ category.title }}</h5>\n                                                  </a>\n                                                  <ul\n                                                       class=\"nav d-md-flex d-none flex-column font-ss ff-ubuntu color-white submenu\">\n                                                       <li class=\"text-uppercase mb-2\"\n                                                            *ngFor=\"let child of category.children\">\n                                                            <a [routerLink]=\"child.path\">\n                                                                 {{ child.title }}\n                                                            </a>\n                                                       </li>\n                                                  </ul>\n                                             </div>\n                                        </div>\n                                   </div>\n                              </div>\n                         </div>\n                    </ul>\n               </li>\n               <li class=\"dropdown separador-left\">\n                    <a [routerLink]=\"'collection/'\"\n                         class=\"color-white color-hover-golden ff-ubuntu-light py-md-2 py-3 px-4 font-sm\"\n                         role=\"button\">\n                         NOVEDADES\n                    </a>\n               </li>\n               <li class=\"dropdown separador-left\">\n                    <a [routerLink]=\"'/collection/attributes/ofertas'\"\n                         class=\"color-white color-hover-golden ff-ubuntu-light py-md-2 py-3 px-4 font-sm\"\n                         role=\"button\">\n                         OFERTAS\n                    </a>\n               </li>\n               <li class=\"dropdown separador-left\">\n                    <a [routerLink]=\"'/section/quienes-somos'\"\n                         class=\"color-white color-hover-golden ff-ubuntu-light py-md-2 py-3 px-4 font-sm\"\n                         role=\"button\">\n                         QUIENES SOMOS\n                    </a>\n               </li>\n               <li class=\"dropdown separador-left\">\n                    <a [routerLink]=\"'/contact'\"\n                         class=\"color-white color-hover-golden ff-ubuntu-light py-md-2 py-3 px-4 font-sm\"\n                         role=\"button\">\n                         CONTACTO\n                    </a>\n               </li>\n          </ul>\n     </nav>\n</header> -->",
            styles: [".no-banner{position:relative!important}"]
        })
    ], HeaderEcComponent);
    return HeaderEcComponent;
}(ComponentHelper));
export { HeaderEcComponent };
//# sourceMappingURL=data:application/json;base64, 