/**
 * @since Wed Oct 24 2018
 * @author Zia ur-Rehman - Klean
 */


import { Component, OnInit }        from '@angular/core'
import { Router, NavigationEnd }    from '@angular/router'

import { FooterTemplate }                           from '@k-core/modules/footer/template/cmp.footer'
import { AppHelper }                                from '@k-settings/app-helper'


//State
import { makeStateKey, DomSanitizer, TransferState } from '@angular/platform-browser'


import { website, store }                  from '@k-settings/app-setup'

// Services
import { FooterService }            from '@k-core/modules/footer/services/svc.footer'
import { MenuService }              from '@k-services/svc.menu'
import { HelperService }            from '@k-services/svc.helper'


// Keys for TransferState data
const SITEINFO = makeStateKey('siteInfoKey')
const FOOTERMENU = makeStateKey('footerMenuKey')

@Component({
    moduleId: module.id+ '',
    selector: 'footer-suntex',
    templateUrl: './tpl.footer.suntex.pug',
    styleUrls: ['./sty.footer.suntex.scss'],

})

export class FooterSuntexTemplate extends FooterTemplate implements OnInit {

    // ---- Variables ---- \\
    website: string = website
    store: string = store
    siteInfo: any

    hideIt: boolean = false;



    constructor(
        _sanitizer: DomSanitizer,
        _footerService: FooterService,
        _menuService: MenuService,
        _helper: HelperService,
        _state: TransferState,
        private _router: Router
    ) {

        // Calling parent constrcutor
        super(_sanitizer, _footerService, _menuService, _helper, _state)

        _router.events.subscribe((event) => {

            if (event instanceof NavigationEnd ) {

                let currentUrlArray = _router.url.split('/')
                                
                if (currentUrlArray[1] === AppHelper.configurator) {

                    console.log('Must be hidden')

                    // Hide here 
                    this.hideIt = true

                } else {
                    this.hideIt = false

                }

            }
        });

    }


    // ngOnInit() {

    //     // pulls and adds SiteInfo to TransferState
    //     this.siteInfo = this.state.get(SITEINFO, null as any)

    //     if(!this.siteInfo) {

    //         this._footerService.getFooter(true).then((response: any) => {
    //             this.siteInfo = response.siteInfo
    //             this.state.set(SITEINFO, response.siteInfo as any)
    //         })
    //     }

    // }


    /**
     * strips spaces from a string, returns it without spaces
     * 
     * @param {string} phone
     * @returns {string}
     */
    stripNumber(phone: string): string {

        let result = ''


        if(!!phone) {

            for(let number of phone.split(' ')) {
                result += number
            }
        }

        return result
    }
}