<?php

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound -- APD is the established namespace shared with the Pro add-on and retained for backward compatibility.
namespace APD\Gutenberg;

use APD\Admin\AdminSettings;

defined('ABSPATH') || exit;

class BlockRegistration
{
    public function __construct(protected ?AdminSettings $settings = null)
    {
        $this->settings ??= new AdminSettings();
    }

    public function register() : void
    {
        register_block_type('asuka/designer', [
            'api_version' => 2,
            'render_callback' => [new BlockRender(), 'render'],
            'attributes' => $this->attributes(),
        ]);
    }

    public function attributes() : array
    {
        $settings = $this->settings->all();

        return [
            'id' => ['type' => 'number', 'default' => 0],
            'mode' => ['type' => 'string', 'default' => (string) ($settings['default_mode'] ?? 'standalone')],
            'height' => ['type' => 'string', 'default' => (string) ($settings['default_height'] ?? '720px')],
        ];
    }
}
