<?php

namespace Blazemedia\Affiliation\Rendering;

use Blazemedia\Affiliation\API\CachedApi;
use Blazemedia\Affiliation\Rendering\Utils\RandomClassGenerator;

class Table extends RenderingTemplate {

    public function __construct( string $shortcode = 'affiliate_table', string $format = 'table', string $format_id = 'table_id' ) {

        parent::__construct( $shortcode, $format, $format_id );
    }

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

        $params = $this->pageData->getParams([
            
            'format'     => $this->format,
            'format_id'  => $atts[ $this->format_id ],
            'link_id'    => 0,
            'extra'      => urlencode(json_encode( [] ))
        ]);

        
        /// richiede il markup del link
        $this->getFormatData( $params );

        $this->randomizeClassForAdBlockers();

        return $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);
    }
}


