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

import { ActivatedRoute }       from '@angular/router'
import { Cookie }               from 'ng2-cookies/ng2-cookies'
import { isPlatformBrowser } 	from '@angular/common'
import { LibraryService }       from '../../../services/svc.library'

@Component({
	moduleId: module.id+'',
	selector: 'access-granted',
	templateUrl: 'tpl.access-granted.pug',
	providers: [LibraryService]
})
export class AccessGrantedView {

	access: any;

	 constructor(
		private route: ActivatedRoute,
		private _library: LibraryService
	) { }

	ngOnInit() {

		this._library.grantAccess().then(response => {
			this.access = response

			if(isPlatformBrowser) {
				Cookie.delete('library')
				Cookie.set('library', 'true')

				if(Cookie.get('library') == 'true') {
					this.access = true
				}
			}
		})
	}
}