<?php

namespace Fab\Controller;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

use Fab\Interfaces\JIT_Interface;

/**
 * Base Block Class
 *
 * @package    Fab
 * @subpackage Fab/Controller
 */
class Block extends Controller implements JIT_Interface {

    /**
     * Enqueue block assets
     * - This is required to support FAB blocks in the editor because enqueue directly using admin_enqueue_scripts won't work.
     *
     * @return void
     */
    public function enqueue_block_assets() {
        // Early return if not in the editor.
        if ( ! is_admin() ) {
            return;
        }

        // Enqueue Backend & Tailwind CSS.
        \FAB()->Helper->wp_enqueue_style_sass( 'fab', 'assets/css/backend/style.scss' );

        // Load vendors.
        \FAB()->Helper->wp_enqueue_style( 'fontawesome', apply_filters( 'fab_fontawesome_css', 'vendor/fontawesome/css/all.min.css' ) );
    }

    /*
    |--------------------------------------------------------------------------
    | Fulfill implemented interface contracts
    |--------------------------------------------------------------------------
     */

    /**
     * JIT method.
     *
     * @return void
     */
    public static function jit() {
        // Enqueue block assets.
        add_action( 'enqueue_block_assets', array( __CLASS__, 'jit_enqueue_block_assets' ) );
    }
}
