<?php
/**
 * Tab: Menu (Free)
 * @package Panelra
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }
$pnlrdb_menu_names = get_option( 'pnlrdb_menu_names', array() );
global $menu;
?>
<h2 class="ap773-section-title"><?php esc_html_e( 'Menu', 'panelra-dashboard-builder' ); ?></h2>
<p class="ap773-section-desc"><?php esc_html_e( 'Rename main menu items. Leave blank to keep the original name.', 'panelra-dashboard-builder' ); ?></p>

<div class="ap773-card">
	<div class="ap773-card-title">
		<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
		<?php esc_html_e( 'Rename menu items', 'panelra-dashboard-builder' ); ?>
	</div>
	<table class="ap773-table">
		<thead>
			<tr>
				<th><?php esc_html_e( 'Original label', 'panelra-dashboard-builder' ); ?></th>
				<th><?php esc_html_e( 'Custom label', 'panelra-dashboard-builder' ); ?></th>
			</tr>
		</thead>
		<tbody>
		<?php if ( is_array( $menu ) ) : foreach ( $menu as $pnlrdb_item ) :
			if ( empty( $pnlrdb_item[0] ) || empty( $pnlrdb_item[2] ) || false !== strpos( $pnlrdb_item[2], 'separator' ) ) { continue; }
			$pnlrdb_slug   = $pnlrdb_item[2];
			$pnlrdb_orig   = wp_strip_all_tags( $pnlrdb_item[0] );
			$pnlrdb_custom = isset( $pnlrdb_menu_names[ $pnlrdb_slug ] ) ? $pnlrdb_menu_names[ $pnlrdb_slug ] : '';
		?>
			<tr>
				<td>
					<?php echo esc_html( $pnlrdb_orig ); ?>
					<span class="ap773-slug"><?php echo esc_html( $pnlrdb_slug ); ?></span>
				</td>
				<td>
					<input type="text" class="ap773-input"
					       name="pnlrdb_menu_names[<?php echo esc_attr( $pnlrdb_slug ); ?>]"
					       value="<?php echo esc_attr( $pnlrdb_custom ); ?>"
					       placeholder="<?php echo esc_attr( $pnlrdb_orig ); ?>"
					       style="max-width:260px;">
				</td>
			</tr>
		<?php endforeach; endif; ?>
		</tbody>
	</table>
</div>

<?php
// Hook per il Pro (drag & drop, submenu rename)
do_action( 'pnlrdb_after_menu_settings' );
do_action( 'pnlrdb_after_menu_settings' );
