<?php
declare(strict_types=1);

namespace ProudNerds\Block;
use ProudNerds\Block\Context;

abstract class BaseBlock implements Block
{
    /**
     * @var string
     */
    public static $slug = '';

    public function getSlug(): string
    {
        return static::$slug;
    }

    public function getName(): string
    {
        return Block::NAME_PREFIX.$this->getSlug();
    }

    /**
     * The user-friendly description
     *
     * This as shown in the sidemenu of the Wordpress admin when the block
     * is selected.
     */
    public function getDescription(): string
    {
        return '';
    }

    /**
     * The category slug
     *
     * This is the category in which the block is shown in the 'Add block'
     * menu. You may choose from the Block::CATEGORY_* constants.
     * Use Block::CATEGORY_SITE to use the current site name as category.
     */
    public function getCategory(): string
    {
        return Block::CATEGORY_SITE;
    }

    /**
     * The icon background color
     *
     * This is a html color name or hex code. This color is shown as background
     * for the block button in the Wordpress 'Add block' menu.
     *
     * Return null to not use a background color.
     */
    public function getIconBackgroundColor(): ?string
    {
        return null;
    }

    /**
     * An array of keywords
     *
     * These keywords are used when searching for a block in the Wordpress
     * 'Add block' menu.
     *
     * This is optional, if no keywords are needed, return an empty array.
     */
    public function getKeywords(): array
    {
        return [];
    }

    /**
     * Return true if you want the user to have the possibility to edit
     * the variables of the block in-place. By default, you can return false.
     */
    public function hasModeSwitch(): bool
    {
        return false;
    }

    /**
     * Return true if you want to enable jsx rendering for this block.
     * This is necessary for blocks that want to support <innerblocks />
     * https://www.advancedcustomfields.com/resources/acf_register_block_type/#examples
     */
    public function enableJSX(): bool
    {
        return false;
    }

    /**
     * Update the block context
     *
     * Here, you can add, remove or change the context before it is
     * passed to Twig (within twig, access this context by using
     * {{ block }}
     */
    public function extendContext(Context $context): void
    {
    }

    /**
     * Set the post types on which this block is available
     *
     * Return an array of post-type strings to only make this block
     * available on those post types.
     * Return null to allow this block on all post types.
     *
     */
    public function getAllowedPostTypes(): ?array
    {
        return null;
    }

    /**
     * Set the page templates on which this block is available
     *
     * Return an array of page template filenames to only make this block
     * available on those page templates, e.g.
     * return ['page-contact.php'];
     * Return null to allow this block on all post types.
     *
     */
    public function getAllowedPageTemplates(): ?array
    {
        return null;
    }

    /**
     * Is this block active and allowed to be registered?
     *
     * Return false to disable registring this block.
     */
    public function isActive(): bool
    {
        return true;
    }
}
