<?php
declare(strict_types=1);

namespace AuraBuilder\Widgets\Basic;

use AuraBuilder\Document\Node;
use AuraBuilder\Widgets\WidgetBase;

final class SpacerWidget extends WidgetBase {

	public function get_type(): string {
		return 'spacer';
	}

	public function get_title(): string {
		return 'Espaço';
	}

	public function get_category(): string {
		return 'layout';
	}

	public function get_icon(): string {
		return 'move-vertical';
	}

	public function get_defaults(): array {
		return array( 'height' => 40 );
	}

	public function get_controls(): array {
		return array(
			array(
				'type' => 'number',
				'name' => 'height',
				'label' => 'Altura (px)',
				'min'  => 8,
				'max'  => 300,
			),
		);
	}

	public function sanitize_settings( array $settings ): array {
		$h = isset( $settings['height'] ) ? absint( $settings['height'] ) : 40;
		return array( 'height' => min( 300, max( 8, $h ) ) );
	}

	public function render( Node $node, array $context = array() ): string {
		$h = (int) ( $node->settings['height'] ?? 40 );
		return '<div class="ab-spacer" style="height:' . $h . 'px" aria-hidden="true"></div>';
	}
}
