<?php
/**
 * Shared admin stylesheet for every WPAgently screen inside wp-admin.
 *
 * The style is registered on every admin screen and enqueued only on the WPAgently
 * screens. Registering unconditionally is deliberate: the separate wp-agent-power
 * plugin declares this handle as a dependency of its own stylesheet, and a handle
 * that is merely registered is still resolved and printed by WordPress.
 */

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

/**
 * The screen hook suffixes that receive the stylesheet.
 *
 * These were read off a live installation (do_action( 'admin_menu' ) plus the
 * runtime hook WordPress passes to admin_enqueue_scripts), not derived from the
 * menu slugs: the two OAuth screens are registered with a null parent, so
 * WordPress names them `admin_page_<slug>`, and the licence screen lives under
 * Tools, so it is `tools_page_<slug>`.
 *
 * @return string[]
 */
function wpagent_companion_admin_style_screens(): array {
	return array(
		'toplevel_page_wpagently',
		'wpagently_page_wpagently-connect',
		'wpagently_page_wpagently-context',
		'wpagently_page_wpagently-live-editor',
		'wpagently_page_wpagently-chat',
		'admin_page_wpagently-oauth-authorize',
		'admin_page_wpagently-oauth-device',
		'tools_page_wpagently-license',
	);
}

function wpagent_companion_admin_base_assets( string $hook ): void {
	$plugin_file = WPAGENT_COMPANION_DIR . 'wp-agent-companion.php';
	wp_register_style(
		'wpagently-admin-base',
		plugins_url( 'assets/admin-base.css', $plugin_file ),
		array(),
		WPAGENT_COMPANION_VERSION
	);
	if ( in_array( $hook, wpagent_companion_admin_style_screens(), true ) ) {
		wp_enqueue_style( 'wpagently-admin-base' );
	}
}
add_action( 'admin_enqueue_scripts', 'wpagent_companion_admin_base_assets', 5 );
