<?php
/**
 * Abstract Block Class
 *
 * @package NemtlyBooking\Blocks
 */

namespace NemtlyBooking\Blocks;

/**
 * Abstract Block class
 */
abstract class Abstract_Block {

    /**
     * Block Namespace
     *
     * @var string
     */
    protected $namespace = 'nemtly';

    /**
     * Block Name
     *
     * @var string
     */
    protected $block_name = '';

    /**
     * Initialize the block
     */
    public function __construct() {
        // Any initialization logic if needed
    }

    /**
     * Get the full block name (namespace/block_name)
     *
     * @return string
     */
    public function get_name() {
        return $this->namespace . '/' . $this->block_name;
    }

    /**
     * Register the block
     */
    public function register() {
        $block_json_path = NEMTLY_BOOKING_PATH . 'assets/js/blocks/' . $this->block_name . '/block.json';

		if ( file_exists( $block_json_path ) ) {
			register_block_type(
                $block_json_path,
                [
					'render_callback' => [ $this, 'render' ],
				]
            );
		} else {
			// Fallback to name-based registration (legacy or if build missing)
			register_block_type(
				$this->get_name(),
				[
					'render_callback' => [ $this, 'render' ],
				]
			);
		}
    }

    /**
     * Render the block
     *
     * @param array    $attributes Block attributes.
     * @param string   $content    Block content.
     * @param \WP_Block $block      Block instance.
     * @return string
     */
    abstract public function render( $attributes, $content, $block );
}
