import { Component, OnInit }        from "@angular/core";
import { Location }                 from '@angular/common';

import { ActivatedRoute, Params }   from '@angular/router'

import { HelperService }            from '../../../services/svc.helper'

import { SeoService }               from '../../../services/svc.seo'
import { StudioService }            from '../../../services/svc.studios'
import { PageService }              from '../../../services/svc.page'

import { PageType }                 from '../../../types/page'


import { Cookie }                   from 'ng2-cookies/ng2-cookies'

@Component({
    moduleId: module.id+ '',
    selector: 'studio-overview-view',
    templateUrl: './tpl.studio-overview.pug'
})

export class StudioOverviewView {

    studios: any;

    pageContent: PageType;

    constructor(
        private _route: ActivatedRoute,
        private studioService: StudioService,
        private _location: Location,
        private _page: PageService,
        private _seo : SeoService,
        private _helper: HelperService
    ) {
    }

    server: string = this._helper.server

    ngOnInit() {
        this.studioService.getStudios().then(response => {
            this.studios = response
        })

        // Get current location, strip first occurrence of `/`
        let urlKey:string = this._location.path();
        if(urlKey.match(/\/.+/)){
            urlKey = urlKey.replace('/', '');
        }

        // Get page content
        this._page.getPageContent(urlKey)
        .then((content) => {
            this.pageContent = content;

            // Set SEO
            this._seo.setTitle(content.meta.title);
            this._seo.updateTag('description', content.meta.description);
        });
    }
}
