<?php

namespace Blazemedia\Affiliation\Rendering;
use Blazemedia\Affiliation\Rendering\Utils\RandomClassGenerator;


class ParseCard extends RenderingTemplate {

    public function __construct() {
   
        parent::__construct( 'parse_card', 'parsecard' );
    }

    // trait per gestire i link che sono 
    // inseriti direttamente in pagina
    // e non tramite link-provider
    use DirectLink\Params; 

    /**
     * Stampa il bottone impostato da shortcode, pri   
     */
    public function manageLink( $atts, $content, $tag ) {

        $program = strtolower( $atts['program'] ); // { 'amazon', 'ebay' }

        /// ricava i parametri per i link inseriti direttamente in pagina
        $directLinkParams = $this->getDirectLinkParams( $program, $atts['link'] ) ;

        $directLinkParams['format_id'] = $atts['format_id']; // id ricavato dal formatprovider 

        $params = $this->pageData->getParams( $directLinkParams );

        $this->getFormatData( $params );

        $this->randomizeClassForAdBlockers();

        /// richiede il markup del link
        return str_replace( '{title}', $content, $this->markup );
    
    }

    function randomizeClassForAdBlockers() { 

        // randomize class for adblockers
        $random_class_markup = RandomClassGenerator::getInstance();

        $this->markup = str_replace('blz_grid', $random_class_markup->getRandomClass() , $this->markup);
    }

    public function insertCSS() { }
}


