<?php

namespace Blazemedia\Affiliation\Rendering;

/** 
 */
class PrintPaidJs {


    public function __construct() {

        //enque script
        add_action( 'wp_enqueue_scripts', [ $this, 'loadPaidDependencies' ], 1);
        
    }


    public function loadPaidDependencies() {

        $isPaid =  PrintPaidJs::isPaid();

        if($isPaid) {
            wp_enqueue_script( 'PaidManager', BLAZE_AFFILIATION_URI .'/js/PaidManager.js' );
            wp_add_inline_script( 'PaidManager', 'const BLZ_API_RENDERING_MANAGER = "'.BLZ_API_RENDERING_MANAGER.'"', 'before' );
        } 
    }

    public static function isPaid() {

        $post = get_post();

        return has_term( 'paid', 'blz_affiliation_attributes', $post->ID );
    }

}