<?php
declare(strict_types=1);

namespace AuraBuilder\Widgets\Basic;

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

final class MenuAnchorWidget extends WidgetBase {
	public function get_type(): string { return 'menu_anchor'; }
	public function get_title(): string { return 'Âncora de menu'; }
	public function get_icon(): string { return 'anchor'; }
	public function get_defaults(): array {
		return array( 'anchor' => 'secao' );
	}
	public function sanitize_settings( array $settings ): array {
		$a = sanitize_title( (string) ( $settings['anchor'] ?? 'secao' ) );
		if ( $a === '' ) {
			$a = 'secao';
		}
		return array( 'anchor' => $a );
	}
	public function render( Node $node, array $context = array() ): string {
		$id = esc_attr( (string) ( $node->settings['anchor'] ?? 'secao' ) );
		$ed = ! empty( $context['editor'] )
			? '<span class="ab-anchor-label"># ' . esc_html( $id ) . '</span>'
			: '';
		return '<div class="ab-menu-anchor" id="' . $id . '">' . $ed . '</div>';
	}
}
