<?php
/**
 * File Path: includes/helpers/class-mbs-sortable-ui.php
 *
 * Sortable UI Helper
 *
 * Static helpers that render the canonical drag-and-drop sort controls used
 * across the plugin admin UI: the PRO-gated dashicons-menu drag handle and
 * the up/down arrow fallback buttons.
 *
 * CSS classes produced:
 *   .mbs-drag-handle       -- dashicons hamburger grip (PRO only).
 *   .mbs-reorder-controls  -- wrapper for up/down fallback buttons.
 *   .mbs-reorder-move-up   -- move-up button inside wrapper.
 *   .mbs-reorder-move-down -- move-down button inside wrapper.
 *
 * JavaScript counterpart : assets/js/adminjs/mbs-sortable-list.js (MBS.SortableList).
 * Stylesheet              : assets/css/admin/mbs-sortable.css
 *
 * @package    My_Book_Showroom
 * @since      1.4.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class MBS_Sortable_UI { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the drag handle span for a sortable row.
	 *
	 * Outputs a dashicons-menu span (PRO). For FREE tier outputs an HTML comment
	 * placeholder so page structure stays consistent without a non-functional element.
	 *
	 * @since 1.4.0
	 *
	 * @param bool $is_pro Whether the current license tier grants drag-and-drop sort.
	 * @return void
	 */
	public static function drag_handle( bool $is_pro = true ): void {
		if ( $is_pro ) {
			?>
			<span class="mbs-drag-handle dashicons dashicons-menu"
			      title="<?php esc_attr_e( 'Drag to reorder', 'my-book-showroom' ); ?>"
			      aria-hidden="true"></span>
			<?php
		} else {
			echo "\n\t\t\t<!-- MBS: drag-and-drop sort requires PRO license -->\n";
		}
	}

	/**
	 * Render the up/down arrow fallback controls for a sortable row.
	 *
	 * Outputs a .mbs-reorder-controls div containing move-up and move-down
	 * button.button-link elements. These serve as the no-JS / FREE-tier fallback
	 * for drag-and-drop sort. MBS.SortableList hides this wrapper when jQuery UI
	 * Sortable activates on the list.
	 *
	 * @since 1.4.0
	 *
	 * @param string $up_label   Screen-reader aria-label for the move-up button.
	 * @param string $down_label Screen-reader aria-label for the move-down button.
	 * @return void
	 */
	public static function reorder_buttons( string $up_label, string $down_label ): void {
		?>
		<div class="mbs-reorder-controls">
			<button type="button"
			        class="button-link mbs-reorder-move-up"
			        aria-label="<?php echo esc_attr( $up_label ); ?>"
			        title="<?php esc_attr_e( 'Move up', 'my-book-showroom' ); ?>">
				<span class="dashicons dashicons-arrow-up-alt2" aria-hidden="true"></span>
			</button>
			<button type="button"
			        class="button-link mbs-reorder-move-down"
			        aria-label="<?php echo esc_attr( $down_label ); ?>"
			        title="<?php esc_attr_e( 'Move down', 'my-book-showroom' ); ?>">
				<span class="dashicons dashicons-arrow-down-alt2" aria-hidden="true"></span>
			</button>
		</div><!-- /.mbs-reorder-controls -->
		<?php
	}
}
