// TODO: Replace cookie service with ngx-cookie

import { Component, OnInit, Input } 	from '@angular/core'
import { Cookie } 				from 'ng2-cookies'

@Component({
	moduleId: module.id + '',
	selector: 'static-block-cookie-promo',
	templateUrl: './tpl.cookie-promo.pug',
	styleUrls: ['./bld.cookie-promo.scss', './sty.cookie-promo.scss']
})
export class CookiePromoComponent implements OnInit {

	// Variables ----
	@Input('static-block') promoContent
	cookieName 			= 'wn-cookiePromo'
	showPromo: boolean 	= false

	constructor() { }



	// Lifecycle hooks ---
	ngOnInit() {

		if(!Cookie.check(this.cookieName)){
			//this.getPromoText();
			this.showPromo = true;
		}
	}




	// Functions ----

	/**
	 * Close promo and set cookie
	 */
	dismissPromo() {
		this.showPromo = false;
		Cookie.set(this.cookieName, 'dismissed')
	}


	/**
	 * Get the promo text
	 */
	getPromoText() {
		// TODO: Get text from backend

		this.promoContent = {'title': 'Gratis levering på alle ordrer', 'content': 'Levering på 2-3 hverdage · 30 dages returret'}

	}


}