<?php

defined( 'ABSPATH' ) || exit;

add_action( 'init', function() {

    if ( ! function_exists( 'register_block_type' ) ) {
        return;
    }

    wp_register_script(
        'willro-reviews-block',
        WILLRO_REVIEWS_URL . 'assets/js/block.js',
        [ 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor' ],
        filemtime( WILLRO_REVIEWS_PATH . 'assets/js/block.js' ),
        true
    );

    wp_register_style(
        'willro-reviews-style',
        WILLRO_REVIEWS_URL . 'assets/css/style.css',
        [],
        filemtime( WILLRO_REVIEWS_PATH . 'assets/css/style.css' )
    );

    register_block_type( 'willro/reviews', [
        'title'           => __( 'Willro Reviews', 'willro-reviews' ),
        'keywords'        => [ 'willro', 'review', 'reviews', 'rating' ],
        'category'        => 'widgets',
        'icon'            => 'star-filled',
        'editor_script'   => 'willro-reviews-block',
        'editor_style'    => 'willro-reviews-style',
        'style'           => 'willro-reviews-style',
        'render_callback' => 'Willro_Reviews_Renderer::render',
        'attributes'      => [
            'template' => [
                'type'    => 'number',
                'default' => 1,
            ],
            'limit' => [
                'type'    => 'number',
                'default' => 10,
            ],
            'mediaType' => [
                'type' => 'string',
            ],
            'sortType' => [
                'type' => 'string',
            ],
            'rating' => [
                'type' => 'string',
            ],
        ],
    ] );


});
