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

/**
 * Asset-Loader-Filter, Block-Registrierung, Textdomain und block_type_metadata-Filter.
 */

add_filter('style_loader_src', function ($src) {
    return ce_pd_bust_plugin_src($src);
}, 99);

add_filter('script_loader_src', function ($src) {
    return ce_pd_bust_plugin_src($src);
}, 99);

add_action('init', function () {
    if (!function_exists('register_block_type')) return;
    register_block_type(CE_PD_DIR . 'blocks/pop3d-diagram', [
        'render_callback' => 'ce_pd_render_block',
    ]);
});

add_action('init', function () {
    /** CE_PD_DIR ist garantiert der Plugin-Root; basename ergibt den Plugin-Ordner relativ zu wp-content/plugins/. */
    // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Expliziter languages/-Pfad; konsistent mit Script-Modul-Jed-JSONs und self-hosted Nutzung.
    load_plugin_textdomain('pop3d-charts', false, basename(rtrim(CE_PD_DIR, '/\\')) . '/languages/');
}, 5);

/** Block-Inserter-Titel/Beschreibung. Editor (edit.js): Übersetzungen in languages/pop3d-charts-*-3dfcabd35eae28d56d07f0f1657e8177.json */
add_filter('block_type_metadata', function ($metadata) {
    if (!is_array($metadata)) {
        return $metadata;
    }
    $name = $metadata['name'] ?? '';
    if ($name === 'pop3d-charts/diagram') {
        $metadata['title'] = __('Pop3D Charts – 2D/3D Data Visualizer', 'pop3d-charts');
        $metadata['description'] = __('Create interactive 2D and 3D charts in the WordPress Block Editor.', 'pop3d-charts');
        return $metadata;
    }
    return $metadata;
}, 10, 1);
