<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if (!class_exists('babBlock')) {
    class babBlock {
        public function __construct() {
            add_action('init', [$this, 'onInit']);
            add_action('enqueue_block_editor_assets', [$this, 'BACEnqueueEditorAssets']);
            add_action('enqueue_block_assets', [$this, 'BACEnqueueFrontendAssets']);
        }
        public function onInit() {
            register_block_type(__DIR__ . '/build');
        }
        public function BACEnqueueEditorAssets() {
            if ( wp_script_is('bab-accordion-editor-script', 'registered') ) {
                wp_add_inline_script(
                    'bab-accordion-editor-script',
                    'const bAIsPipeChecker = ' . wp_json_encode(bab_is_premium()) . ';',
                    'before'
                );
            }
        }
        public function BACEnqueueFrontendAssets() {
            if ( wp_script_is('bab-accordion-view-script', 'registered') ) {
                wp_add_inline_script(
                    'bab-accordion-view-script',
                    'const bAIsPipeChecker = ' . wp_json_encode(bab_is_premium()) . ';',
                    'before'
                );
            }
        }
    }

    new babBlock();
}