<?php

declare(strict_types=1);

namespace Australcode\Rewards\Admin;

defined( 'ABSPATH' ) || exit;

/**
 * Adapter over the Australcode Admin Kit's canonical header partials
 * (`assets/acds/page-header.php` + `section-header.php`, installed by
 * `acds-sync.sh`). Option 2 / app-bar (decision 8.121): the bar is the PLUGIN
 * identity — product icon-256 + constant EN name + monospace version badge +
 * `<hr class="wp-header-end">` (L-029: without the marker WP injects
 * admin_notices INSIDE the flex header and breaks the layout). The VIEW name
 * (H2) + lede + actions drop into the content as the kit's section-header.
 * Centralising both in a trait keeps every Australcode Points and Rewards admin
 * page coherent and lets the Verde Austral re-skin reach this plugin through the
 * kit instead of a private fork (L-043).
 *
 * The plugin keeps its Dashboard-hub navigation model (a "← Dashboard" back
 * action on every page except the Dashboard) — rendered as a section-header
 * action, so the bar needs no tab strip.
 *
 * Callers must open the page wrapper before calling this: the kit header
 * expects to live inside `<div class="wrap acds-root acrwd-page"><div class="acds-wrap">`.
 */
trait RendersPageHeader {

	/**
	 * @param array<string,string> $actions Map of url => label rendered as buttons.
	 */
	protected function render_page_header( string $title, string $lede, array $actions = array() ): void {
		// App-bar (Opción 2, decisión 8.121): la barra es la identidad del PLUGIN —
		// icon-256 del producto + nombre EN constante + versión, sin tabs (modelo
		// Dashboard-hub). El nombre de la VISTA + lede + acciones (incl. "← Dashboard")
		// bajan al section-header del kit.
		$acds_title    = 'Australcode Points and Rewards';
		$acds_version  = ACRWD_VERSION;
		$acds_mark_url = ACRWD_URL . 'assets/acds/icons/icon-256-points-rewards.svg';
		$acds_actions  = '';
		$acds_tabs     = array();

		require ACRWD_PATH . 'assets/acds/page-header.php';

		// Section-header: nombre de la VISTA (H2) + lede + acciones.
		$acds_section_actions = '';
		foreach ( $actions as $url => $label ) {
			$acds_section_actions .= '<a class="acds-btn acds-btn--secondary acds-btn--sm" href="' . esc_url( $url ) . '">'
				. esc_html( $label ) . '</a>';
		}
		$acds_section_title = $title;
		$acds_section_lede  = $lede;
		require ACRWD_PATH . 'assets/acds/section-header.php';
	}

	/**
	 * URL of the Rewards Dashboard, for the canonical "← Dashboard" back action.
	 *
	 * @return array<string,string>
	 */
	protected function dashboard_back_action(): array {
		return array( admin_url( 'admin.php?page=acrwd' ) => '← ' . __( 'Dashboard', 'australcode-points-rewards' ) );
	}
}
