<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class IDSC_Assets {

    private static $needs_css = false;
    private static $needs_js  = false;

    public function __construct() {
        add_action( 'wp_footer', array( $this, 'maybe_enqueue' ), 5 );
    }

    public static function flag_css() {
        self::$needs_css = true;
    }

    public static function flag_js() {
        self::$needs_js = true;
    }

    public function maybe_enqueue() {
        if ( self::$needs_css ) {
            wp_enqueue_style(
                'idsc-blocks',
                IDSC_PLUGIN_URL . 'assets/css/idsc-blocks.css',
                array(),
                IDSC_VERSION
            );
        }

        if ( self::$needs_js ) {
            wp_enqueue_script(
                'idsc-blocks',
                IDSC_PLUGIN_URL . 'assets/js/idsc-blocks.js',
                array(),
                IDSC_VERSION,
                true
            );
        }
    }
}
