import { Component, OnInit } from '@angular/core'
import { FooterTemplate } from '@k-core/modules/footer/template/cmp.footer'
import { makeStateKey } from '@angular/platform-browser'


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

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

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

})

export class FooterStof2000Template extends FooterTemplate implements OnInit {
    website: string = website
    siteInfo: any
    footerMenu: any

    ngOnInit() {


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

        if(!this.siteInfo) {

            this._helper.siteData$.subscribe((response: any) => {
                this.siteInfo = response.siteInfo
                this.state.set(SITEINFO, response.siteInfo as any)
            })
        }

        // Pulls and adds footer-menu to TransferState
        this.footerMenu = this.state.get(FOOTERMENU, null as any)

        if(!this.footerMenu) {

            this._menuService.getMenu('footer-menu').then((response) => {
                this.footerMenu = response
                this.state.set(FOOTERMENU, response 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
    }
}