<?php

namespace Convertforce\Blocks;

abstract class Base {

    protected static $localize = false;
    abstract public static function render($attributes, $content);

    abstract public static function get_build_dir_name();
    
    public static function localize_script($script_handle) {}

    public static function register() {
        $block_class = get_called_class();
        $block_name = static::get_build_dir_name();
        
        $block_type = register_block_type_from_metadata(CONVERTFORCE_DIR . '/build/blocks/' . $block_name . '/block.json', [
            'render_callback' => [$block_class, 'render']
        ]);
        
        if (static::$localize && $block_type && !empty($block_type->editor_script_handles)) {
            $script_handle = $block_type->editor_script_handles[0];
            static::localize_script($script_handle);
        }
    }

}