/**
 * @since Mon Sep 03 2018
 * @author Charles Gouldmann - Klean
 */

import { Inject, Injectable } from '@angular/core'
import { DOCUMENT, Title, Meta } from '@angular/platform-browser'

import { AppHelper } from '@k-settings/app-helper'


@Injectable()
export class SeoService extends Title {
  private _document

  constructor(
    @Inject(DOCUMENT) document,
    private _title: Title,
    private _meta: Meta
  ) {
    super(document)
    this._document = document
  }

  // ---- Variables ---- \\
  prefix    = AppHelper.showSeoPrefix ? AppHelper.seoPrefix : ''
  seperator = AppHelper.showSeoPrefix ? ' - ' : ''



  // ---- Functions ---- \\
  /**
   * Get the title of the current HTML document.
   * @returns {string}
   */
  getTitle(): string {
    return this._document.title
  }


  /**
   * Set the title of the page and choose to show prefix or not.
   * @param newTitle
   * @param hidePrefix
   */
  setTitle(newTitle: string, hidePrefix?: boolean): void {
    newTitle = (hidePrefix ? newTitle : this.prefix + this.seperator + newTitle)
    this._title.setTitle(newTitle)
  }
  

  /**
   * Uses metaService to update meta tag.
   * @param name
   * @param content
   */
  updateTag(name, content): void {
    if(content != null)
      this._meta.updateTag(
          {name: name, content: content} 
      )
  }


}