<?php

namespace Plugins\GoogleTagPlugin;

use Core\View\View;
use Core\View\ElementView;

use Apps\EeApp\Entity\EeAppPlugin;

class GoogleTagPlugin{

    public $Author = 'Webemyos';
    public $Version = '1.0.0.0';
    
    function __construct($core) {
        $this->Core = $core;
    }
    
    
    /*     * *
     * Seo Type
     */

    function GetType() {
        return "Seo";
    }
    
     /*     * *
     * Render the Js in the VotePlugin
     */

    function GetRegisterPlugin() {
    }
    
    /***
     * 
     */
    function GetRegister(){
    }
   
    /***
     * Render Gogle Tag Manager Script
     */
    function Render($tag){

        return "<!-- Google tag (gtag.js) -->
        <script async src='https://www.googletagmanager.com/gtag/js?id=".$tag."'></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());

          gtag('config', '".$tag."');
        </script>" ;
    }

    /***
     * Config Form
     */
    function RenderConfigForm($pluginId){

        $view = new View(__DIR__ . "/View/config.tpl", $this->Core);
        $view->AddElement(new ElementView("pluginId", $pluginId));
       
        $plugin = new EeAppPlugin($this->Core);
        $plugin->GetById($pluginId);
        $parameters = json_decode($plugin->Parameters->Value);
       
        $view->AddElement(new ElementView("clientId", $parameters->clientId));
       
        return $view->Render();
    }

}